Commit ef04cb4
authored
perf: inline fields, shared keys, and concrete Members for objComp/mapWithKey (#758)
## Summary
- **Shared allKeyNames/visibleKeyNames** (Val.Obj): Objects from the
same `MemberList` expression now lazily share key-name arrays via a
`_sourceMemberList` reference on `Val.Obj`. The first access computes
and caches on the MemberList AST node; subsequent objects reuse the
shared arrays.
- **Inline field arrays for visitObjComp**: Apply the same `singleKey ->
inlineKeys -> builder` tiered storage from `visitMemberList` to object
comprehensions, avoiding `LinkedHashMap` for comprehensions producing
1-8 fields.
- **Concrete ObjCompMember/MapWithKeyMember classes**: Replace anonymous
`Val.Obj.Member` inner classes in `visitObjComp` and `std.mapWithKey`
with concrete final classes for monomorphic JIT dispatch.
- **Inline field arrays for std.mapWithKey**: Use
`singleFieldKey`/`inlineFieldKeys` constructor paths for mapped objects
with up to 8 keys, sharing the source object's `allKeyNames` array
directly.
- **Remove fieldLookups/fieldCacheHits counters**: These DebugStats
counters in `Val.Obj.value()` were bloating the method past the JIT
inlining threshold, causing a ~5% regression on bench.02.
## Benchmark results (vs pre-optimization baseline at 8c33fd9)
| Benchmark | Baseline (ms/op) | After (ms/op) | Change |
|---|---|---|---|
| bench.02 | 76.368 | 73.352 | -3.9% |
| bench.07 | 9.948 | 5.254 | **-47.2%** |
| comparison | 6.941 | 4.204 | **-39.4%** |
| large_string_template | 5.591 | 3.806 | **-31.9%** |
| large_string_join | 1.476 | 1.048 | **-29.0%** |
| base64 | 1.150 | 0.820 | **-28.7%** |
| setDiff | 1.373 | 0.999 | **-27.2%** |
| setUnion | 1.969 | 1.461 | **-25.8%** |
| base64_byte_array | 2.925 | 2.198 | **-24.9%** |
| realistic1 | 4.592 | 3.534 | **-23.0%** |
| bench.04 | 0.486 | 0.375 | **-22.8%** |
| foldl | 0.277 | 0.215 | **-22.4%** |
| setInter | 1.072 | 0.838 | **-21.8%** |
| substr | 0.212 | 0.174 | **-17.9%** |
| realistic2 | 115.444 | 98.109 | **-15.0%** |
All other benchmarks improved or within noise. No regressions.
## Test plan
- [x] `./mill 'sjsonnet.jvm[3.3.7]'.test` — all 3 test suites pass
- [x] `./mill __.checkFormat` — formatting clean
- [x] `./mill bench.runRegressions` — no regressions1 parent 82301d7 commit ef04cb4
5 files changed
Lines changed: 236 additions & 81 deletions
File tree
- sjsonnet/src/sjsonnet
- stdlib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
| |||
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
62 | | - | |
63 | | - | |
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1748 | 1748 | | |
1749 | 1749 | | |
1750 | 1750 | | |
1751 | | - | |
| 1751 | + | |
| 1752 | + | |
1752 | 1753 | | |
1753 | | - | |
| 1754 | + | |
1754 | 1755 | | |
1755 | 1756 | | |
1756 | 1757 | | |
| |||
1767 | 1768 | | |
1768 | 1769 | | |
1769 | 1770 | | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
1770 | 1775 | | |
1771 | 1776 | | |
1772 | 1777 | | |
1773 | 1778 | | |
1774 | 1779 | | |
1775 | 1780 | | |
1776 | | - | |
1777 | 1781 | | |
1778 | 1782 | | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
1779 | 1792 | | |
1780 | 1793 | | |
1781 | 1794 | | |
1782 | | - | |
1783 | | - | |
1784 | | - | |
1785 | | - | |
1786 | | - | |
1787 | | - | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
1791 | | - | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
1792 | 1832 | | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
1793 | 1836 | | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
1797 | 1841 | | |
| 1842 | + | |
1798 | 1843 | | |
1799 | 1844 | | |
1800 | 1845 | | |
1801 | 1846 | | |
1802 | 1847 | | |
1803 | | - | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
1804 | 1884 | | |
1805 | 1885 | | |
1806 | 1886 | | |
| |||
2098 | 2178 | | |
2099 | 2179 | | |
2100 | 2180 | | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
2101 | 2202 | | |
2102 | 2203 | | |
2103 | 2204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
419 | 431 | | |
420 | 432 | | |
421 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
689 | 696 | | |
690 | 697 | | |
691 | 698 | | |
| |||
987 | 994 | | |
988 | 995 | | |
989 | 996 | | |
990 | | - | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
991 | 1000 | | |
992 | | - | |
993 | | - | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
994 | 1009 | | |
995 | 1010 | | |
996 | 1011 | | |
997 | 1012 | | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1013 | 1042 | | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
1019 | 1051 | | |
1020 | 1052 | | |
1021 | 1053 | | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
| 1054 | + | |
| 1055 | + | |
1034 | 1056 | | |
1035 | 1057 | | |
1036 | 1058 | | |
1037 | 1059 | | |
1038 | | - | |
1039 | | - | |
1040 | 1060 | | |
1041 | 1061 | | |
1042 | 1062 | | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
| 1063 | + | |
1046 | 1064 | | |
1047 | 1065 | | |
1048 | 1066 | | |
1049 | 1067 | | |
1050 | 1068 | | |
1051 | 1069 | | |
1052 | 1070 | | |
1053 | | - | |
1054 | 1071 | | |
1055 | 1072 | | |
1056 | 1073 | | |
1057 | | - | |
1058 | 1074 | | |
1059 | 1075 | | |
1060 | 1076 | | |
1061 | 1077 | | |
1062 | | - | |
1063 | 1078 | | |
1064 | 1079 | | |
1065 | 1080 | | |
| |||
0 commit comments