opt(caching): reduce ProgramCache lock contention#955
Open
Haihan-Jiang wants to merge 1 commit into
Open
Conversation
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #955 +/- ##
==========================================
- Coverage 51.86% 51.42% -0.45%
==========================================
Files 127 170 +43
Lines 10893 14186 +3293
==========================================
+ Hits 5650 7295 +1645
- Misses 4920 6500 +1580
- Partials 323 391 +68
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
optimize
Check the PR title.
(Optional) Translate the PR title into Chinese.
减少 ProgramCache 的锁竞争
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
This reduces
ProgramCache.Compute()lock contention on cache misses.Before this change,
Compute()held the global cache mutex while running the potentially expensivecompute()function. That serialized all cache-miss compilations, even when goroutines were compiling unrelated*rt.GoTypevalues.This PR adds a small per-type in-flight call table:
Reset()prevents an older in-flight compile from repopulating the fresh cache;zh(optional):
这个 PR 减少
ProgramCache.Compute()在 cache miss 时的锁竞争。之前
Compute()会在执行可能较慢的compute()时一直持有全局 cache mutex,导致不同*rt.GoType的编译也被串行化。本 PR 增加了一个按类型区分的 in-flight call 表:
Reset()后,旧的 in-flight 编译不会重新写入新 cache;compute()panic,会清理 pending entry 并继续 panic,避免后续同类型调用被永久卡住。(Optional) Which issue(s) this PR fixes:
Fixes #948
Test Results
All passed locally.
I also tried
go test ./...on Darwin/ARM64 with Go 1.26.3. The full run still has existing platform/JIT build failures in packages such asinternal/decoder/jitdec,internal/encoder/x86,internal/jit,internal/native/avx2, andinternal/native/sse; the targetedinternal/cachingpackage passed.