Commit 3e2f43d
committed
perf(stmtcache): replace O(n) invalidation scan with O(1) map lookup
Replace linear slice scan in LRUCache.Put() with hash map lookup for
invalidated statement tracking. Maintains both invalidStmts slice and
invalidSet map to optimize both Put() and GetInvalidated() operations.
Performance impact (Apple M1 Pro):
- Baseline: 1.41x faster (178ns → 126ns)
- 100 invalidations: 1.56x faster (203ns → 131ns)
- 500 invalidations: 2.21x faster (287ns → 130ns)
- Worst case (re-adding invalidated): 3.85x faster (570ns → 148ns)
Original implementation degrades from 178ns to 570ns as invalidations
accumulate. Optimized version maintains constant ~130ns performance
regardless of invalidation count.
Memory overhead: ~8 bytes per invalidated statement. No API changes.
Signed-off-by: Mathias Bogaert <mathias.bogaert@gmail.com>1 parent f2d5d44 commit 3e2f43d
1 file changed
Lines changed: 15 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
0 commit comments