Commit 03736fb
committed
perf(redis): bounded Lua VM pool — r1 review fixes
Round-1 review fixes on commit 972e1da:
1. gemini medium @ redis_lua_pool.go get() — centralize binding/return
Refactor the three-branch select (hit / nil-element fallback /
empty pool) so the ctxBinding assignment and return happen
exactly once after the select. Pure restructuring; behaviour
and metrics are unchanged.
2. gemini medium @ redis_lua_pool.go put() — fast-path drop before reset
Skip pls.reset() when len(p.idle) already equals maxIdle. The
reset walks every globals / tables / metatables snapshot and is
the most expensive part of put(); doing it for a state that
will immediately be Close()'d in the channel-full branch is
wasted work the EVAL hot path would feel under sustained
saturation.
Race-safety: len() on a buffered channel is an atomically-loaded
snapshot, so the fast-path can lose a race with a concurrent
recv (empty channel that we mistakenly skip-and-drop is fine —
that's equivalent to picking up a tiny drop budget) or win a
race with a concurrent send (full channel that we correctly
drop — saves one reset). The existing select-based drop branch
stays in place as the correctness fallback when the snapshot
was stale.
Caller audit (semantic change in put — drop happens before
reset): only production caller is adapter/redis_lua.go:135
(`defer luaPool.put(pls)`). The caller does not touch pls
after put; the externally visible behaviour (put returns, state
may be reused later) is unchanged. No callers grep'd that
depend on the reset-then-drop ordering.
3. golangci magic-number @ main.go — derive flag default from
adapter.DefaultLuaPoolMaxIdle
Export defaultLuaPoolMaxIdle → DefaultLuaPoolMaxIdle and use
adapter.DefaultLuaPoolMaxIdle as the --redisLuaMaxIdleStates
flag default. Single source of truth, removes the mnd lint.
4. golangci gci @ adapter/redis.go, main.go — auto-format
`golangci-lint fmt` cleanup, no semantic change.
Test:
go test -race -count=1 -run "TestLua_Pool|TestLua_VMReuse" ./adapter
-- green.
golangci-lint run --config=.golangci.yaml ./adapter/ . -- 0 issues.1 parent 972e1da commit 03736fb
4 files changed
Lines changed: 94 additions & 72 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
| 293 | + | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
446 | | - | |
| 446 | + | |
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
227 | 232 | | |
228 | 233 | | |
229 | 234 | | |
230 | | - | |
| 235 | + | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
234 | 239 | | |
235 | | - | |
| 240 | + | |
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
239 | 244 | | |
240 | | - | |
| 245 | + | |
241 | 246 | | |
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
245 | | - | |
| 250 | + | |
246 | 251 | | |
247 | 252 | | |
248 | 253 | | |
| |||
527 | 532 | | |
528 | 533 | | |
529 | 534 | | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
534 | 544 | | |
| 545 | + | |
535 | 546 | | |
536 | | - | |
537 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
538 | 551 | | |
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
542 | | - | |
543 | | - | |
544 | 555 | | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | 556 | | |
549 | 557 | | |
550 | | - | |
551 | | - | |
552 | | - | |
| 558 | + | |
553 | 559 | | |
| 560 | + | |
| 561 | + | |
554 | 562 | | |
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
558 | 566 | | |
559 | 567 | | |
560 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
561 | 580 | | |
562 | 581 | | |
563 | 582 | | |
| |||
571 | 590 | | |
572 | 591 | | |
573 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
574 | 598 | | |
575 | 599 | | |
576 | 600 | | |
577 | 601 | | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 602 | + | |
| 603 | + | |
582 | 604 | | |
583 | 605 | | |
584 | 606 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
692 | | - | |
| 692 | + | |
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| |||
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
710 | | - | |
711 | | - | |
| 710 | + | |
| 711 | + | |
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
0 commit comments