-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve start-up time #60
Comments
Dynamic imports seem like a good first step, from your investigation seems wise not to import every available format's parser/unparser on load :) Update from #65 (comment):
|
I looked into this further because, apart from the bad UX, the observed sluggishness slows down test-driven development. I was hoping to get an easy to implement speed up by fixing the synchronous loading of JSON Schemas in I therefore did some experiments to try and isolate which modules, if any, where causing slowness. In In each iteration, TS was compiles to JS and 10 iterations done (with npm run build:dist
bash -c "time for i in {1..10}; do node dist/cli ; done" In the final iterations, I removed some of the slowest-to-load modules just to confirm this. Note that
Some summary thoughts:
import * as csv from './csv'
//...
await dump(await csv.encode(datatable)) but it should do this: import * as dump from '.'
//...
await dump(datatable, 'csv') |
#125 makes some substantial improvements to startup times through dynamic loading of codec modules. Profiling suggests that the next candidate for optimisation should be to make the loading and compilation of JSON schemas by Ajv both lazy and asynchronous. The offending lines are Lines 19 to 25 in 484e461
and Lines 69 to 73 in 484e461
(and a similar block for "mutators") I think the most most pragmatic approach to improving performance here would be to make the Lines 84 to 87 in 484e461
we should lazily and asynchronously read the if (!validator) {
const schema = await fs.readJSON(path.join(built, `${type}.schema.json`))
validator = ajv.addSchema(schema)
.compile(schema);
} |
🎉 This issue has been resolved in version 0.53.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The start up time of the CLI is curiously high. On Linux, using the binary it takes about 1s:
bash -c "time for i in {1..10}; do bin/stencila-convert --version; done" 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 0.33.0 real 0m9.936s user 0m12.604s sys 0m0.868s
In comparison,
nixster
takes 0.1s anddockter
takes 0.25s (both are built usingpkg
).I experimented with commenting out
import './boot'
fromcli.ts
and the time (with a binary) was almost exactly the same. However when I commented outimport { convert } from './index'
it fell to 0.15s. So it may simply be the amount of code that needs to be interpreted by Node at startup time that is causing the slowness. Would using dynamicrequire()
calls be a way around this?Note sure if we should address this now - that could be premature optimisation.
The text was updated successfully, but these errors were encountered: