-
Notifications
You must be signed in to change notification settings - Fork 22
perf: cache json initialization #43
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
Conversation
|
Are there performance concerns reported upstream? Or is this optimization for its own sake? Removing dependency on spdx-license-ids may work a small load-time improvement, but it will also prevent relatively frequent updates to that package from flowing through to this package via I may have fallen behind on changes to the various |
There is no concern upstream, I'm just a dev with free time and willing to speedup npm run.
That's a valid concern, but I think you can solve this by using
You are right on this one:
Good question, from what I saw, is just for legacy purposes, so I will try to lazy load the initialization of this module. But currently, importing this module will have a penalty of In case you don't want to ship the JSONs, I will totally understand! If so, can we at least lazy load the initialization to when this module is being called? I think this will be the ideal world, to leave the penalty only when this module is actually being used. |
|
If you're hunting perf gains, I'm guessing the real prize is in npm. I don't know what legacy As for this package alone, I'm disinclined to make a chore of lockstep releases, especially premature of any perf complaints. It's not a pure win, given how often this package gets bundled with other spdx-related packages. I'm not if this is being used in any Web client-side apps, but space matters, too. Frankly, mostly it's my time that I value. I try to avoid making chores for myself. |
|
That's okay, totally valid reasons. Before closing this PR, do you think is valid to create a PR to lazy load the initialization of |
|
I'm not exactly sure I know what you mean. But if you're feeling inspired to PR while you've got it fresh in mind, I'll earnestly review your proposal. Maybe not this evening—it's 1930 here—but when I can. |
|
I created the PR at #44 Take your time, I really appreciate your review, as a perf guy, I just look at the perf gains without thinking much about the other "costs" of the code. And for me it's almost midnight, so I'm going to rest now ahahha |
I was doing some perf for
npm runand I found thesortTranspositionswas taking 5ms to run.So, I changed the code to be like
spdx-license-idsand generated a JSON with the calculatedtranspositionsand also with thelast-resorts.I also lazy load the dependencies to only import when needed, so we do not introduce any perf penalty for those who import this module but will not use it immediately.
In this way, we remove one dependency and we also improve the initialization of this module:
Before:
$ hyperfine --warmup 3 "node ./index.js" [22:38:45] Benchmark 1: node ./index.js Time (mean ± σ): 109.3 ms ± 1.1 ms [User: 95.4 ms, System: 38.1 ms] Range (min … max): 107.2 ms … 111.9 ms 27 runsAfter:
$ hyperfine --warmup 3 "node ./index.js" [22:36:37] Benchmark 1: node ./index.js Time (mean ± σ): 101.0 ms ± 1.1 ms [User: 88.5 ms, System: 34.1 ms] Range (min … max): 99.2 ms … 103.6 ms 29 runs