We have noticed that using native private class members is ~95% slower than normal properties. That puts them into the same ballpark as the WeakMap-workaround that's commonly used/emitted today. https://jsbench.me/0gljcn4wzt/2 is a benchmark that compares * native privates * weakmap polyfill privates * publics I have tested this with Safari 16.5.1 and latest Tech Preview. Other browsers also show inferior performance but not as dramatic.
<rdar://problem/111836716>
I can replicate these numbers on my M1 Macbook Air using latest STP. The performance drop for native private fields is greater in JSC than V8. Safari TP #private fields: 35 ops/sec Safari TP public fields: 632 ops/sec Chome Canary #private fields: 62 ops/sec Chome Canary public fields: 107 ops/sec This is surprising.
Created attachment 467196 [details] microbenchmark that can be run from jsc shell
I've attached a microbenchmark that can be run from the jsc shell directly. ``` ❯ jsc -m out.js cpu: unknown runtime: unknown (unknown) benchmark time (avg) (min … max) p75 p99 p995 ------------------------------------------------------------ ----------------------------- Polyfillprivate 81.76 ms/iter (79.48 ms … 84.84 ms) 82.04 ms 84.84 ms 84.84 ms NativePrivates 41.32 ms/iter (40.31 ms … 43.61 ms) 41.76 ms 43.61 ms 43.61 ms ConventionalPrivates 919.52 µs/iter (619.67 µs … 2.65 ms) 780.25 µs 1.95 ms 1.96 ms ```