Commit 2b5b738
committed
history: speed up load with ReadFile and strconv.Unquote
Replace json.NewDecoder streaming decode with os.ReadFile + string
splitting + strconv.Unquote. The history file stores one JSON-quoted
string per line; Unquote handles the same escapes without the full
JSON state machine and reflection overhead.
Pre-size slices by counting newlines upfront and use map[string]struct{}
for deduplication to reduce allocation count.
Benchmarked on a 658KB / 7348-line history file:
Before: 3.05ms, 15703 allocs, 2.32MB
After: 1.41ms, 2606 allocs, 2.96MB
Assisted-By: docker-agent1 parent 644522e commit 2b5b738
1 file changed
Lines changed: 36 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | 215 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
225 | 245 | | |
226 | 246 | | |
227 | 247 | | |
228 | 248 | | |
229 | 249 | | |
230 | | - | |
231 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
232 | 253 | | |
233 | | - | |
| 254 | + | |
234 | 255 | | |
235 | 256 | | |
236 | | - | |
| 257 | + | |
237 | 258 | | |
238 | 259 | | |
239 | 260 | | |
| |||
0 commit comments