Commit 37fbaf0
committed
refactor: drop freshBit side-channel — derive hit/miss symmetrically
With Swift's Set<pointer> and JS's Map<pointer, wrapper> updated at the
same cache boundaries and keyed identically, the freshBit signal is
redundant. Swift can use Set.insert(ptr).inserted to detect a miss in a
single op; JS can use Map.get(pointer) and check for undefined.
Swift return-lowering simplifies to:
let ptr = Unmanaged.passUnretained(ret).toOpaque()
if _<Class>_identityTable.insert(ptr).inserted {
_ = Unmanaged.passRetained(ret)
}
return ptr
JS __wrap simplifies to:
const cached = __swiftIdentityWrappers.get(pointer)
if (cached !== undefined) return cached
// build wrapper, insert into Map
No stack push/pop per return on the swift-mode path. Swift heap-object
lifetime invariants unchanged.
Performance (500k iters, median ms, swift mode only):
v3 v4 delta vs v3 vs pointer vs none
passBothWaysRoundtrip 27 26 -4% -17% -84%
getPoolRepeated_100 34 32 -6% -31% -83%
swiftCreatesObject 347 593 +71% (CV noise; see below)
churnObjects 332 317 -5% -60% -99%
swiftConsumesSameObject 17 10 parity parity -42%
swift mode is now a strict Pareto improvement over pointer mode on every
scenario: faster on hit, faster on miss, faster on churn, parity on the
one-way path. The swiftCreatesObject v3→v4 number is noisy across runs
(37% CV) — the v3 standalone 347ms and v4 three-way 593ms overlap within
CV; both are ~5x faster than pointer mode's 2021ms and within 15-30% of
the 'none' baseline (514ms).
165/165 tests green.1 parent 03df22f commit 37fbaf0
8 files changed
Lines changed: 84 additions & 232 deletions
File tree
- Benchmarks/Sources/Generated
- Plugins/BridgeJS
- Sources
- BridgeJSCore
- BridgeJSLink
- Tests/BridgeJSToolTests/__Snapshots__
- BridgeJSCodegenTests
- BridgeJSLinkTests
- Tests
- BridgeJSIdentityTests/Generated
- BridgeJSSwiftIdentityTests/Generated
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1824 | 1824 | | |
1825 | 1825 | | |
1826 | 1826 | | |
1827 | | - | |
1828 | | - | |
1829 | | - | |
1830 | | - | |
| 1827 | + | |
| 1828 | + | |
1831 | 1829 | | |
1832 | | - | |
1833 | | - | |
1834 | | - | |
1835 | 1830 | | |
1836 | 1831 | | |
1837 | 1832 | | |
| |||
1969 | 1964 | | |
1970 | 1965 | | |
1971 | 1966 | | |
1972 | | - | |
1973 | | - | |
1974 | | - | |
| 1967 | + | |
| 1968 | + | |
1975 | 1969 | | |
1976 | | - | |
1977 | | - | |
1978 | | - | |
1979 | 1970 | | |
1980 | 1971 | | |
1981 | 1972 | | |
| |||
2012 | 2003 | | |
2013 | 2004 | | |
2014 | 2005 | | |
2015 | | - | |
2016 | | - | |
2017 | | - | |
2018 | | - | |
| 2006 | + | |
| 2007 | + | |
2019 | 2008 | | |
2020 | | - | |
2021 | | - | |
2022 | | - | |
2023 | 2009 | | |
2024 | 2010 | | |
2025 | 2011 | | |
| |||
2034 | 2020 | | |
2035 | 2021 | | |
2036 | 2022 | | |
2037 | | - | |
2038 | | - | |
2039 | | - | |
2040 | | - | |
| 2023 | + | |
| 2024 | + | |
2041 | 2025 | | |
2042 | | - | |
2043 | | - | |
2044 | | - | |
2045 | 2026 | | |
2046 | 2027 | | |
2047 | 2028 | | |
| |||
2056 | 2037 | | |
2057 | 2038 | | |
2058 | 2039 | | |
2059 | | - | |
2060 | | - | |
2061 | | - | |
2062 | | - | |
| 2040 | + | |
| 2041 | + | |
2063 | 2042 | | |
2064 | | - | |
2065 | | - | |
2066 | | - | |
2067 | 2043 | | |
2068 | 2044 | | |
2069 | 2045 | | |
| |||
2106 | 2082 | | |
2107 | 2083 | | |
2108 | 2084 | | |
2109 | | - | |
2110 | | - | |
2111 | | - | |
| 2085 | + | |
| 2086 | + | |
2112 | 2087 | | |
2113 | | - | |
2114 | | - | |
2115 | | - | |
2116 | 2088 | | |
2117 | 2089 | | |
2118 | 2090 | | |
| |||
2149 | 2121 | | |
2150 | 2122 | | |
2151 | 2123 | | |
2152 | | - | |
2153 | | - | |
2154 | | - | |
2155 | | - | |
| 2124 | + | |
| 2125 | + | |
2156 | 2126 | | |
2157 | | - | |
2158 | | - | |
2159 | | - | |
2160 | 2127 | | |
2161 | 2128 | | |
2162 | 2129 | | |
| |||
2210 | 2177 | | |
2211 | 2178 | | |
2212 | 2179 | | |
2213 | | - | |
2214 | | - | |
2215 | | - | |
| 2180 | + | |
| 2181 | + | |
2216 | 2182 | | |
2217 | | - | |
2218 | | - | |
2219 | | - | |
2220 | 2183 | | |
2221 | 2184 | | |
2222 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
365 | 363 | | |
366 | 364 | | |
367 | 365 | | |
368 | 366 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 367 | + | |
| 368 | + | |
373 | 369 | | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | 370 | | |
378 | 371 | | |
379 | 372 | | |
| |||
781 | 774 | | |
782 | 775 | | |
783 | 776 | | |
784 | | - | |
785 | | - | |
| 777 | + | |
| 778 | + | |
786 | 779 | | |
787 | 780 | | |
788 | 781 | | |
789 | 782 | | |
790 | 783 | | |
791 | | - | |
792 | | - | |
793 | | - | |
| 784 | + | |
| 785 | + | |
794 | 786 | | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | 787 | | |
799 | 788 | | |
800 | 789 | | |
| |||
Lines changed: 10 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2060 | 2060 | | |
2061 | 2061 | | |
2062 | 2062 | | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
2066 | 2067 | | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
2071 | 2072 | | |
2072 | 2073 | | |
2073 | 2074 | | |
2074 | 2075 | | |
2075 | 2076 | | |
2076 | 2077 | | |
2077 | | - | |
2078 | | - | |
2079 | | - | |
2080 | | - | |
2081 | | - | |
2082 | | - | |
| 2078 | + | |
| 2079 | + | |
2083 | 2080 | | |
2084 | 2081 | | |
2085 | 2082 | | |
| |||
Lines changed: 4 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
| 11 | + | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 13 | | |
19 | 14 | | |
20 | 15 | | |
| |||
68 | 63 | | |
69 | 64 | | |
70 | 65 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 66 | + | |
| 67 | + | |
74 | 68 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 69 | | |
79 | 70 | | |
80 | 71 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 311 | + | |
| 312 | + | |
315 | 313 | | |
316 | 314 | | |
317 | 315 | | |
| |||
Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeSwiftClass.js
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 276 | + | |
| 277 | + | |
280 | 278 | | |
281 | 279 | | |
282 | 280 | | |
| |||
0 commit comments