Reduce NodeState memory by 128 B via lazy locks and Interlocked - #4425
Draft
marcschier wants to merge 2 commits into
Draft
Reduce NodeState memory by 128 B via lazy locks and Interlocked#4425marcschier wants to merge 2 commits into
marcschier wants to merge 2 commits into
Conversation
Replace the dedicated event-monitor counter field with Interlocked/Volatile operations and a clamped decrement. Lazily publish the notifier and browse Lock fields with CompareExchange, preserving lock ordering. Add concurrency tests and allocation benchmarks. Public API is unchanged; constructor allocation reduced by 128 B per node on net10.0 x64. Relates to #4275 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d2569e2e-7115-4969-bb44-8159e302b450
Code coverage✅ Coverage gate passed.
Uncovered changed lines
Coverage is above the recorded baseline - consider ratcheting Thresholds live in |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4425 +/- ##
==========================================
+ Coverage 80.70% 80.87% +0.16%
==========================================
Files 1959 1984 +25
Lines 272896 276994 +4098
Branches 47380 48073 +693
==========================================
+ Hits 220242 224020 +3778
- Misses 36173 36437 +264
- Partials 16481 16537 +56
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d2569e2e-7115-4969-bb44-8159e302b450
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.
Description
Reduce
NodeStateconstructor allocation by 128 B per node on net10.0 x64 by replacing eager lock-object allocation with lock-free primitives and lazy initialization:Lockfield in favor ofInterlocked/Volatileoperations and a clamped decrement, eliminating one heap allocation per node constructor call.Lockfields usingInterlocked.CompareExchange, preserving the browse → notifier → reference lock ordering.Final net10.0 x64 allocation results:
masterBaseObjectStateBaseDataVariableStateThe matched ShortRun benchmark showed no warm-path regression: warm browse was 69.7 ns on this branch versus 76.4 ns on
master. The contended benchmark is scheduler-sensitive, but allocation is identical and the direct warmed path is unchanged after lazy publication.Related Issues
Checklist
Put an
xin the boxes that apply. You can complete these step by step after opening the PR.Local validation summary
Opc.Ua.Types.TestsNodeState category, net10.0Opc.Ua.Types.TestsNodeState category, net48Opc.Ua.Server.Tests, net10.0UA.slnxRelease build withCustomTestTarget=net10.0Opc.Ua.Aot.Testsmanaged Release buildmasterwith the same benchmark sourceEarlier full
Opc.Ua.Types.Testsruns on both TFMs each reached one pre-existing WoT fixture hash failure. The net48Opc.Ua.Server.Testsrun reached a pre-existing certificate-leak teardown failure. Neither failure is in code touched by this PR.