Compile time for an object literal grows far faster than its key count. Runtime is not the problem — the compiled program is much faster than node (quiet host, 5,000 keys: node 1.42 s, perry 0.00 s). The cost is entirely in compilation, and literals this wide appear in generated code and bundled config.
Measured on the dev box with cache-busting unique content and user CPU time:
Shape A — literal + 97 property reads + Object.keys:
| keys |
compile, user CPU |
| 1 |
1.05 s |
| 2,000 |
112.31 s |
Shape B — literal + Object.keys only, no reads:
| keys |
compile, user CPU |
vs previous |
| 250 |
19.71 s |
|
| 500 |
120.95 s |
x6.1 for x2 keys |
| 1,000 |
944.68 s |
x7.8 for x2 keys |
Shape B is roughly n^2.6 to n^3.
Two caveats for whoever picks this up
- The shapes contradict. 2,000 keys in shape A cost 112 s, while 1,000 keys in shape B cost 945 s. Removing the property reads appears to make compilation dramatically worse, which would itself be the finding — or it is measurement error. Not resolved.
- Load. Every number was taken at load average 77-104.
user CPU is far less load-sensitive than wall clock, which is why it is quoted, but the contradiction above means the exponent is not established. Re-run both shapes on a quiet host before quoting a complexity class.
Measurement notes
The object cache makes a repeat compile of the same source meaningless — the first attempt at this measurement was a cache hit and read as "no problem". Generate unique content per run.
Done when
Compile time is roughly linear in key count.
Compile time for an object literal grows far faster than its key count. Runtime is not the problem — the compiled program is much faster than node (quiet host, 5,000 keys: node 1.42 s, perry 0.00 s). The cost is entirely in compilation, and literals this wide appear in generated code and bundled config.
Measured on the dev box with cache-busting unique content and user CPU time:
Shape A — literal + 97 property reads +
Object.keys:Shape B — literal +
Object.keysonly, no reads:Shape B is roughly n^2.6 to n^3.
Two caveats for whoever picks this up
userCPU is far less load-sensitive than wall clock, which is why it is quoted, but the contradiction above means the exponent is not established. Re-run both shapes on a quiet host before quoting a complexity class.Measurement notes
The object cache makes a repeat compile of the same source meaningless — the first attempt at this measurement was a cache hit and read as "no problem". Generate unique content per run.
Done when
Compile time is roughly linear in key count.