Commit 2cd26a2
committed
perf(tsort): optimize HashMap and Vec allocation to reduce benchmark regression
- Pre-allocate HashMap with capacity 64 in Graph::new to avoid resizing
- Pre-allocate Vec with capacity 4 in Node::default for typical node degree
- Addresses tsort_input_parsing_heavy[5000] -2.55% regression (82.7ms -> 84.9ms)
These optimizations eliminate allocation overhead during graph construction:
- HashMap resizing eliminated for graphs with ~70 nodes
- Vec reallocations reduced for nodes with 2-4 successors (typical case)1 parent 3577f24 commit 2cd26a2
1 file changed
+15
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
125 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
144 | 154 | | |
145 | 155 | | |
146 | 156 | | |
147 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
148 | 161 | | |
149 | 162 | | |
150 | 163 | | |
| |||
0 commit comments