Repository navigation
Reduce contention in UnwindInfoTable seen during high volume LCG method creation - #128619
Conversation
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
Pull request overview
This PR targets performance/scalability under high-volume dynamic method (LCG) creation by reducing lock contention and avoiding avoidable allocations in CoreCLR’s dynamic method and unwind-info publishing paths.
Changes:
- Pre-seeds
LCGMethodResolver::m_DynamicCodePointerswith an inline “first” node to avoid chunk allocation in the common single-pointer case. - Reworks
UnwindInfoTablesynchronization to use per-table locks plus a per-table “flush gate” to reduce contention when flushing pending entries. - Increases pending buffer capacity and switches pending sorting and removal operations to more efficient algorithms.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/vm/dynamicmethod.h | Adds an inline initial DynamicCodePointer node and initializes m_DynamicCodePointers to it. |
| src/coreclr/vm/dynamicmethod.cpp | Resets/allocates code pointer records using the inline initial node to avoid allocations under hot locks. |
| src/coreclr/vm/codeman.h | Expands pending buffer and introduces per-table locks, flush gate, and registration-failed state. |
| src/coreclr/vm/codeman.cpp | Implements per-table locking/flush gating, pending sort changes, binary-search removal, and lock-free table installation via CAS. |
Comments suppressed due to low confidence (1)
src/coreclr/vm/codeman.cpp:500
- RemoveFromUnwindInfoTable can incorrectly return after matching a soft-deleted (UnwindData==0) entry in the published table. This is problematic now that we also search the pending buffer: if code addresses are reused, a deleted published entry may still cover the new method’s Begin/End range, causing this path to return early and skip removing the real pending entry. Consider requiring UnwindData != 0 for the published-table match (or otherwise treating deleted matches as not-found so the pending buffer check can run).
if (lo > 0)
{
ULONG i = lo - 1;
if (relativeEntryPoint < RUNTIME_FUNCTION__EndAddress(&unwindInfo->pTable[i], unwindInfo->iRangeStart))
{
if (unwindInfo->pTable[i].UnwindData != 0)
unwindInfo->cDeletedEntries++;
unwindInfo->pTable[i].UnwindData = 0; // Mark the entry for deletion
STRESS_LOG1(LF_JIT, LL_INFO100, "RemoveFromUnwindInfoTable Removed entry 0x%x\n", i);
|
@eduardo-vp you still need minimal repro from us on Linux? based on your comment |
|
@korchak-aleksandr yes, this targets mostly windows. On Linux there's most likely a completely different problem to solve, I couldn't come up with a repro. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
Double checked that there's still a performance improvement up until the latest commit, updated the PR description. |
|
/backport to release/10.0 |
|
Started backporting to |
…volume LCG method creation (#129035) Backport of #128619 to release/10.0 /cc @eduardo-vp ## Customer Impact - [x] Customer reported - [ ] Found internally This regression causes test suites to run up to 1.7x slower on Windows in .NET 10. Issue originally reported in #123124. ## Regression - [x] Yes - [ ] No ## Testing The fix was verified using two benchmarks mentioned in the original PR. I think this is very specific to situations where a high volume of LCG methods are created simultaneously which explains why the issue was previously missed. ## Risk Medium. It changes the behavior of `UnwindInfoTable` to fix the regression. However, the change has been in main for ~3 weeks and no issues have been linked to this PR. **IMPORTANT**: If this backport is for a servicing release, please verify that: - For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`, not `release/X.0`. - For .NET 10+: The PR target branch is `release/X.0` (no `-staging` suffix). ## Package authoring no longer needed in .NET 9 **IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version. Keep in mind that we still need package authoring in .NET 8 and older versions. --------- Co-authored-by: Eduardo Velarde <[email protected]> Co-authored-by: Eduardo Velarde <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Contributes to #123124.
Changes:
m_DynamicCodePointersinLCGMethodResolver. In most cases the list will contain exactly one pointer but if it starts empty, it does a chunk allocation while taking a lock. The initial pointer avoids that unnecessary chunk allocation for most cases.AddToUnwindInfoTableto avoid taking locks unnecessarily.I used both the original xUnit test with 30k methods mentioned in the issue and a separate benchmark that stresses LCG method creation to test these changes. I mostly used the LCG benchmark to investigate this since .NET 10 runs ~150% slower than .NET 9 so it was easier to spot if changes were helpful or not.
For the measurements, I built from release/9.0, release/10.0 and release/10.0 + the changes in this PR since the goal is to backport to net 10.
LCG Stress Benchmark (300K methods)
LCG stress benchmark code
Original regression was considerably slower. Still slower than .NET 9 but at the same time I'm dubious if it's a realistic scenario.
Original xUnit Benchmark (30K methods)
Original regression was ~30%. The original benchmark now runs slower than .NET 9 but much better than before.