Commit cb04d8c
committed
refactor: simplify identity cache — drop compact id, key by pointer
The initial implementation used a Swift-assigned compact Int32 id so that
JS could index a dense Array<wrapper>. In isolation Array[i] is ~2x faster
than Map.get (194ns vs 98ns for 1M integer-keyed lookups), but end-to-end
benchmarks never surfaced that win — the swift-mode hit path came in at
parity with pointer mode regardless. Meanwhile the id machinery carried
real cost: five per-class globals, id allocation + recycling, reverse
lookup dictionary, two i32 push/pop pairs per return.
Swift per-class state: 5 globals → 2
_identityTable: [ptr:id] → Set<ptr>
_idToPointer: [id:ptr] → removed
_wrapperRefs: [Int32] → [ptr:Int32]
_freeIds → removed
_nextId → removed
JS per-class cache: Array<wrapper>[id] → Map<ptr, wrapper>
Stack pushes per return: 2 (id, freshBit) → 1 (freshBit)
Wasm exports: register_wrapper / release_wrapper now take pointer
ABI contract, === semantics, and lifetime guarantees are unchanged.
Performance impact (500k iters, median ms, swift mode only):
v1 v2 delta
passBothWaysRoundtrip 33 28 -15%
getPoolRepeated_100 41 34 -17%
swiftCreatesObject 846 592 -30%
churnObjects 456 438 -4%
Simpler code runs faster; the id-allocation + reverse-dict upkeep was net
negative. 165/165 tests green.1 parent d7e34a5 commit cb04d8c
14 files changed
Lines changed: 292 additions & 766 deletions
File tree
- Benchmarks/Sources/Generated
- Plugins/BridgeJS
- Sources
- BridgeJSCore
- BridgeJSLink
- Tests/BridgeJSToolTests/__Snapshots__
- BridgeJSCodegenTests
- BridgeJSLinkTests
- Tests
- BridgeJSIdentityTests
- Generated
- JavaScript
- JavaScript
- BridgeJSSwiftIdentityTests
- Generated
- JavaScript
- JavaScript
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
362 | 365 | | |
363 | 366 | | |
364 | 367 | | |
365 | 368 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 369 | + | |
| 370 | + | |
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
372 | 374 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
| 375 | + | |
384 | 376 | | |
385 | 377 | | |
386 | 378 | | |
| |||
719 | 711 | | |
720 | 712 | | |
721 | 713 | | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
726 | 721 | | |
727 | 722 | | |
728 | | - | |
| 723 | + | |
729 | 724 | | |
730 | 725 | | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
| 726 | + | |
741 | 727 | | |
742 | 728 | | |
743 | 729 | | |
| |||
781 | 767 | | |
782 | 768 | | |
783 | 769 | | |
784 | | - | |
785 | | - | |
| 770 | + | |
| 771 | + | |
786 | 772 | | |
787 | 773 | | |
788 | 774 | | |
789 | 775 | | |
790 | 776 | | |
791 | | - | |
| 777 | + | |
792 | 778 | | |
793 | 779 | | |
794 | 780 | | |
795 | | - | |
| 781 | + | |
796 | 782 | | |
797 | 783 | | |
798 | 784 | | |
| |||
801 | 787 | | |
802 | 788 | | |
803 | 789 | | |
804 | | - | |
| 790 | + | |
805 | 791 | | |
806 | 792 | | |
807 | 793 | | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
817 | 797 | | |
818 | 798 | | |
819 | 799 | | |
820 | 800 | | |
821 | 801 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
835 | 806 | | |
836 | 807 | | |
837 | 808 | | |
838 | 809 | | |
839 | 810 | | |
840 | | - | |
841 | | - | |
| 811 | + | |
842 | 812 | | |
843 | 813 | | |
844 | 814 | | |
845 | 815 | | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
| 816 | + | |
857 | 817 | | |
858 | 818 | | |
859 | 819 | | |
| |||
Lines changed: 15 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2060 | 2060 | | |
2061 | 2061 | | |
2062 | 2062 | | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
2066 | | - | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
2067 | 2068 | | |
2068 | 2069 | | |
2069 | | - | |
| 2070 | + | |
2070 | 2071 | | |
2071 | 2072 | | |
2072 | 2073 | | |
2073 | | - | |
2074 | | - | |
2075 | 2074 | | |
2076 | | - | |
2077 | 2075 | | |
2078 | 2076 | | |
2079 | | - | |
| 2077 | + | |
2080 | 2078 | | |
2081 | 2079 | | |
2082 | 2080 | | |
2083 | 2081 | | |
2084 | | - | |
2085 | 2082 | | |
2086 | | - | |
| 2083 | + | |
2087 | 2084 | | |
2088 | | - | |
| 2085 | + | |
2089 | 2086 | | |
2090 | | - | |
| 2087 | + | |
2091 | 2088 | | |
2092 | 2089 | | |
2093 | 2090 | | |
2094 | 2091 | | |
2095 | 2092 | | |
2096 | 2093 | | |
2097 | | - | |
2098 | | - | |
2099 | 2094 | | |
2100 | 2095 | | |
2101 | 2096 | | |
| |||
2104 | 2099 | | |
2105 | 2100 | | |
2106 | 2101 | | |
2107 | | - | |
2108 | | - | |
2109 | | - | |
2110 | | - | |
2111 | | - | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
2112 | 2107 | | |
2113 | 2108 | | |
2114 | 2109 | | |
| |||
Lines changed: 13 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 3 | + | |
10 | 4 | | |
11 | 5 | | |
12 | 6 | | |
| |||
15 | 9 | | |
16 | 10 | | |
17 | 11 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 12 | + | |
| 13 | + | |
21 | 14 | | |
22 | 15 | | |
23 | 16 | | |
24 | 17 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 18 | + | |
36 | 19 | | |
37 | 20 | | |
38 | 21 | | |
| |||
74 | 57 | | |
75 | 58 | | |
76 | 59 | | |
77 | | - | |
| 60 | + | |
78 | 61 | | |
79 | | - | |
| 62 | + | |
80 | 63 | | |
81 | 64 | | |
82 | 65 | | |
83 | 66 | | |
84 | 67 | | |
85 | 68 | | |
86 | 69 | | |
87 | | - | |
| 70 | + | |
88 | 71 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
98 | 75 | | |
99 | 76 | | |
100 | 77 | | |
| |||
105 | 82 | | |
106 | 83 | | |
107 | 84 | | |
108 | | - | |
109 | | - | |
| 85 | + | |
110 | 86 | | |
111 | 87 | | |
112 | 88 | | |
113 | 89 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 90 | + | |
125 | 91 | | |
126 | 92 | | |
127 | 93 | | |
| |||
0 commit comments