Skip to content

Commit 68a0e10

Browse files
authored
perf(dx): drastic performance improvements on Replit (#249)
Take free replit's performance from over 3m to under one. Pro replit from over 1 minute to under 10 seconds.
1 parent 9f0531c commit 68a0e10

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

.replit

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,58 @@
11
hidden=[".config", ".github", ".gitignore", ".prettierrc", "quick-start", "react-chat"]
22

33
run = """
4-
if [ ! -x "$(command -v feathers)" ]; then
5-
npm i -g @feathersjs/cli
6-
fi
7-
84
cd feathers-chat-ts
9-
clear
105
npm run dev
116
""" # """
127

138
compile = """ # Runs before debug too. Lacks custom env vars.
9+
SECONDS=0
10+
FEATHERS_DIR="feathers-chat-ts"
1411
clear
15-
echo Running compile...
16-
if [ ! -d "feathers-chat-ts/node_modules" ]; then
17-
cd feathers-chat-ts
18-
npm i
19-
npm run compile
20-
npm run migrate
12+
echo [compile]
13+
14+
if [ ! -d "$FEATHERS_DIR/node_modules" ]; then
15+
cd $FEATHERS_DIR
16+
npm i &> /dev/null
17+
export PERF1=$SECONDS
18+
# npm run migrate # Most of the time, optional
19+
20+
# For TS clients
21+
# npm run compile # Drastically faster dev cold boot without
22+
# npm run bundle:client # Generates .tgz types for loading into TS clients
23+
24+
export PERF2=$(($SECONDS - $PERF1))
2125
cd -
2226
fi
2327

2428
# Helper script to deal with lack of CWD support in the Debugger
2529
mkdir -p .config
2630
if [ ! -f "./.config/replit.mjs" ]; then
2731
cat << EOF > ./.config/replit.mjs
28-
// Resolve FEATHERS_DIR path and cd to it
29-
console.log(process.env.NODE_PATH)
3032
if (process.env.FEATHERS_DIR) {
31-
const p = process.env.FEATHERS_DIR
32-
const f = new Function('return \\`' + p + '\\`;').call(process.env)
33-
process.chdir(f)
33+
process.chdir(process.env.FEATHERS_DIR)
3434
}
3535
EOF
3636
fi
3737

38+
rm tsconfig.json 2> /dev/null || : # Cleanup upstream debris
39+
3840
if [ ! -f "./.config/bashrc" ]; then
3941
cat << EOF > ./.config/bashrc
4042
#!/bin/bash
41-
node --version
43+
echo Node version: "$(node --version)"
4244
EOF
4345
fi
4446

45-
rm tsconfig.json 2> /dev/null || : # Cleanup upstream debris
47+
INDEX_TS="$FEATHERS_DIR/src/index.ts"
48+
if ! grep -q "console.time" "$INDEX_TS"; then
49+
sed -i "1i console.time('App startup time')" "$INDEX_TS"
50+
sed -i "/Feathers app listening on /a console.timeEnd('App startup time')" "$INDEX_TS"
51+
clear
52+
echo "[compile] took ${SECONDS}s. ($PERF1 + $PERF2)"
53+
else
54+
clear
55+
fi
4656
""" # """
4757

4858

@@ -65,21 +75,17 @@ externalPort = 9000
6575
channel = "stable-22_11"
6676

6777
[env]
68-
PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin"
78+
FEATHERS_DIR = "feathers-chat-ts"
79+
PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin:/home/runner/$REPL_SLUG/$FEATHERS_DIR/node_modules/.bin"
6980
EDITOR="replit-git-editor"
70-
npm_config_yes="true"
7181
npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global"
7282
HOSTNAME="0.0.0.0"
7383
NODE_OPTIONS="--max_old_space_size=384"
7484

75-
# Enables Secrets and Repl Auth, without the erratic Replit packagers
85+
# Enables Secrets and Auth, without the Replit packager
7686
[packager]
7787
language = "bash"
7888

79-
# Todo: Currently uses mocha by default, use npm run test instead or Test Runner
80-
# [unitTest]
81-
# language = "nodejs"
82-
8389
[languages.typescript]
8490
pattern = "**/{*.ts,*.js,*.tsx,*.jsx}"
8591
syntax = "typescript"
@@ -133,5 +139,4 @@ support = true
133139

134140
[debugger.interactive.launchMessage.arguments.env]
135141
PORT = 9000
136-
FEATHERS_DIR = "${this.HOME}/${this.REPL_SLUG}/feathers-chat-ts"
137142

replit.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{ pkgs }: {
22
deps = [
3-
pkgs.bashInteractive
43
pkgs.nodejs-19_x
54
pkgs.nodePackages.typescript-language-server
65
];
7-
}
6+
}

0 commit comments

Comments
 (0)