Commit e42ef42
perf: redesign cache pruning based on empirical measurement
Profiling revealed that object.size() overcounts gs_power_npe cache
entries by ~600x (reports 1.8 MB per entry when true incremental cost
is ~3 KB). This is because object.size() walks into shared namespace
environments of function arguments, counting the same gsDesign2
namespace (833 KB) and gsDesign namespace (75 KB) for every entry.
Changes:
- Remove object.size() from the pruning path (both slow and inaccurate)
- Only check entry count before insertions, not on cache hits
- Set max_entries = 1024, justified by:
- True cost: ~3 KB (gs_power_npe) to ~5 KB (ahr) per entry
- 1024 entries ≈ 3-5 MB real memory
- Supports ~200 cached designs in a session
- A single design creates only 5-28 entries
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 7e8d5d5 commit e42ef42
1 file changed
Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | 77 | | |
79 | 78 | | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
0 commit comments