Bug 258660 - private class members are much, much slower than public members
Summary: private class members are much, much slower than public members
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-06-29 02:02 PDT by scythes.corms_0i
Modified: 2023-08-03 18:05 PDT (History)
7 users (show)

See Also:


Attachments
microbenchmark that can be run from jsc shell (20.65 KB, text/javascript)
2023-08-03 18:02 PDT, Jarred Sumner
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description scythes.corms_0i 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.
Comment 1 Radar WebKit Bug Importer 2023-07-06 02:03:13 PDT
<rdar://problem/111836716>
Comment 2 Rob Palmer 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.
Comment 3 Jarred Sumner 2023-08-03 18:02:23 PDT
Created attachment 467196 [details]
microbenchmark that can be run from jsc shell
Comment 4 Jarred Sumner 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
```