Commit 998469b
committed
perf: fix critical vm.runInContext overhead (30x speedup)
CRITICAL FIX:
- vm.Script.runInContext() has 30x overhead on EVERY function call
- Even with cached context, each invocation crosses VM boundary
- Changed to use new Function() for fast path (no context)
- Inject 'require' parameter to maintain Node.js compatibility
BEFORE: turbo(1M items) = 7779ms (36x slower than raw JS)
AFTER: turbo(1M items) = 308ms (1.5x overhead, acceptable)
turbo(8 workers) = 190ms (1.1x FASTER than raw JS!)
This fix affects both:
- dist/worker.js (file workers)
- INLINE_WORKER_CODE (bundled workers)1 parent 3c20c8b commit 998469b
2 files changed
+27
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | 138 | | |
159 | 139 | | |
160 | 140 | | |
| |||
497 | 477 | | |
498 | 478 | | |
499 | 479 | | |
500 | | - | |
| 480 | + | |
501 | 481 | | |
502 | 482 | | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | 483 | | |
510 | | - | |
511 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
512 | 490 | | |
513 | 491 | | |
514 | | - | |
515 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
516 | 496 | | |
517 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
518 | 503 | | |
519 | 504 | | |
520 | 505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 129 | + | |
132 | 130 | | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
136 | | - | |
137 | | - | |
138 | 134 | | |
| 135 | + | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
144 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
429 | | - | |
430 | 428 | | |
431 | 429 | | |
432 | 430 | | |
433 | 431 | | |
434 | 432 | | |
435 | | - | |
436 | | - | |
437 | 433 | | |
| 434 | + | |
| 435 | + | |
438 | 436 | | |
439 | 437 | | |
440 | 438 | | |
441 | 439 | | |
442 | | - | |
| 440 | + | |
| 441 | + | |
443 | 442 | | |
444 | 443 | | |
445 | 444 | | |
| |||
0 commit comments