Bug 258660

Summary: private class members are much, much slower than public members
Product: WebKit Reporter: scythes.corms_0i
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: dpaddock, jarred, mark.lam, rik, rob.palmer2, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
microbenchmark that can be run from jsc shell none

scythes.corms_0i
Reported 2023-06-29 02:02:58 PDT
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.
Attachments
microbenchmark that can be run from jsc shell (20.65 KB, text/javascript)
2023-08-03 18:02 PDT, Jarred Sumner
no flags
Radar WebKit Bug Importer
Comment 1 2023-07-06 02:03:13 PDT
Rob Palmer
Comment 2 2023-08-02 01:04:41 PDT
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.
Jarred Sumner
Comment 3 2023-08-03 18:02:23 PDT
Created attachment 467196 [details] microbenchmark that can be run from jsc shell
Jarred Sumner
Comment 4 2023-08-03 18:05:25 PDT
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 ```
Note You need to log in before you can comment on or make changes to this bug.