Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: don't create duplicate function/object templates for ops (#1010)
We were creating them twice - once when attaching them to `Deno.core.ops`, then creating all new templates when setting up the virtual ops module. That meant that the snapshot included two copies of each template, bloating the snapshot size and hurting snapshot deserialization time. To fix this, just reuse the templates we've already attached to `Deno.core.ops`. This greatly improves the impact of object wrap (and ops in general) on snapshot size and deserialization time. statrtup perf: with 1000 object wrap `DOMPoints` vs 1000 pure JS `DOMPoints` (`dcore-objwrap-1000-opt` is this PR) ``` ❯ hyperfine -w 500 -N "./dcore-js-1000 empty.js" "./dcore-objwrap-1000 empty.js" "./dcore-objwrap-1000-opt empty.js" Benchmark 1: ./dcore-js-1000 empty.js Time (mean ± σ): 10.5 ms ± 0.5 ms [User: 7.4 ms, System: 2.6 ms] Range (min … max): 9.5 ms … 11.7 ms 297 runs Benchmark 2: ./dcore-objwrap-1000 empty.js Time (mean ± σ): 14.7 ms ± 0.7 ms [User: 10.1 ms, System: 3.8 ms] Range (min … max): 13.4 ms … 17.5 ms 203 runs Benchmark 3: ./dcore-objwrap-1000-opt empty.js Time (mean ± σ): 10.4 ms ± 0.6 ms [User: 6.7 ms, System: 3.0 ms] Range (min … max): 9.3 ms … 13.7 ms 275 runs Summary ./dcore-objwrap-1000-opt empty.js ran 1.01 ± 0.08 times faster than ./dcore-js-1000 empty.js 1.41 ± 0.11 times faster than ./dcore-objwrap-1000 empty.js ``` snapshot size (in particular the size of the isolate and context 1 snapshots): ``` ❯ ./dcore-objwrap-1000 --v8-flags=--profile_deserialization empty.js 🛑 deno_core binary is meant for development and testing purposes. Run empty.js [Deserializing read-only space (420972 bytes) took 0.292 ms] [Deserializing isolate (3510040 bytes) took 8.875 ms] [Deserializing context #1 (1863760 bytes) took 5.333 ms] ❯ ./dcore-objwrap-1000-opt --v8-flags=--profile_deserialization empty.js 🛑 deno_core binary is meant for development and testing purposes. Run empty.js [Deserializing read-only space (420972 bytes) took 0.250 ms] [Deserializing isolate (1865184 bytes) took 4.083 ms] [Deserializing context #1 (1007968 bytes) took 2.666 ms] ```
- Loading branch information