Skip to content

Improve Inherited Context Lookup in getConfigResources - #11048

Open
he1l0world wants to merge 10 commits into
apache:mainfrom
he1l0world:improve/config-resources
Open

he1l0world wants to merge 10 commits into
apache:mainfrom
he1l0world:improve/config-resources

Conversation

@he1l0world

@he1l0world he1l0world commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

Description

This PR improves the performance and clarity of the getConfigResources method in the ModuleDefinitionSet class.

Previously, getConfigResources traversed the entire module hierarchy on each call, redundantly re-computing inherited context resources from parent modules. This change introduces memoization using a configResourcesMap. The result is a more efficient and maintainable implementation, especially as the number of modules grows.

The work builds upon PR #11042, which added unit test coverage for this method. With tests in place, this change now optimizes the implementation while maintaining the same expected behavior.

I’m submitting this PR in draft form to:

  • Get feedback on the approach.
  • Make sure it aligns with broader architectural expectations.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Verified using the unit tests introduced in PR #11042

How did you try to break this feature and the system with this change?

Verified that duplicate traversal across inherited modules no longer occurs

@DaanHoogland

Copy link
Copy Markdown
Contributor

good initiative @he1l0world , let’s wait till we have #11042 merged with further work on this one. It would be interesting to see if any positive performance impact is given on startup, by this change.

@codecov

codecov Bot commented Jun 17, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 19.78%. Comparing base (44ab7dd) to head (74d796c).

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #11048   +/-   ##
=========================================
  Coverage     19.77%   19.78%           
- Complexity    19989    19995    +6     
=========================================
  Files          6371     6371           
  Lines        575899   575908    +9     
  Branches      70495    70495           
=========================================
+ Hits         113912   113946   +34     
+ Misses       449563   449533   -30     
- Partials      12424    12429    +5     
Flag Coverage Δ
uitests 3.53% <ø> (ø)
unittests 21.05% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@he1l0world

Copy link
Copy Markdown
Contributor Author

good initiative @he1l0world , let’s wait till we have #11042 merged with further work on this one. It would be interesting to see if any positive performance impact is given on startup, by this change.

Sure!

@he1l0world
he1l0world marked this pull request as ready for review June 20, 2025 03:16
@weizhouapache
weizhouapache requested a lite review from Copilot May 7, 2026 15:20
@weizhouapache weizhouapache added this to the 4.22.1 milestone May 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes Spring module context loading by memoizing inherited (parent-chain) context resources in DefaultModuleDefinitionSet#getConfigResources, reducing repeated hierarchy traversal during module initialization.

Changes:

  • Introduced an internal cache (configResourcesMap) to memoize inherited/inheritable context resources per module.
  • Refactored inherited-resource collection into a helper method (collectInheritedResources) and simplified array creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sureshanaparti sureshanaparti modified the milestones: 4.22.1, 4.23.0 May 8, 2026
@weizhouapache weizhouapache modified the milestones: 4.23.0, 4.24.0 Jun 30, 2026
@nvazquez

Copy link
Copy Markdown
Contributor

Hi @he1l0world is this PR still in progress? Can you please address the review comments?

@DaanHoogland DaanHoogland moved this from Backlog to conflict/waiting for author in CloudStack Testing Aug 31, 2026
@DaanHoogland

Copy link
Copy Markdown
Contributor

@he1l0world are you still interested in this?

@he1l0world

Copy link
Copy Markdown
Contributor Author

Hi @he1l0world is this PR still in progress? Can you please address the review comments?

Sorry, I missed the message. Yes, I think the comments make sense will address them.

@he1l0world

Copy link
Copy Markdown
Contributor Author

@he1l0world are you still interested in this?

Yes will update the PR

Copilot AI review requested due to automatic review settings September 5, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is localized, preserves prior ordering semantics, and the new memoization is consistent with existing module wiring and lifecycle usage.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 5, 2026 01:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new memoization cache is backed by an unsynchronized HashMap mutated from a public method, which can introduce concurrency hazards compared to the previous stateless traversal.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

@DaanHoogland DaanHoogland moved this from conflict/waiting to Backlog in CloudStack Testing Sep 5, 2026
@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19151

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16960)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 62588 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr11048-t16960-kvm-ol8.zip
Smoke tests completed. 156 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm, much more elegant, but also functionally equivilant.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

8 participants