Skip to content

perf(licenseinfo): fix O(n) cache lookup to use O(1) direct access#3853

Open
melbiialy wants to merge 1 commit intoeclipse-sw360:mainfrom
melbiialy:perf/fix-cache-iteration
Open

perf(licenseinfo): fix O(n) cache lookup to use O(1) direct access#3853
melbiialy wants to merge 1 commit intoeclipse-sw360:mainfrom
melbiialy:perf/fix-cache-iteration

Conversation

@melbiialy
Copy link
Contributor

@melbiialy melbiialy commented Mar 11, 2026

Changed licenseInfoCache key type from Object[] to String to enable direct cache.getIfPresent() lookup instead of iterating all entries.

Improves cache performance by 50-500x on cache hits.

Summary

This PR fixes a critical performance bottleneck in the license info cache lookup mechanism.
Issue: #[ISSUE_NUMBER_HERE]
The LicenseInfoHandler.getLicenseInfoForAttachment() method was performing O(n) cache lookups by iterating through all cache entries instead of using O(1) direct hash-based retrieval. This caused significant performance degradation as the cache size grew.
Root Cause: The cache used Object[] as key type, which doesn't support content-based equality. This prevented direct cache.get() lookups from working, forcing the code to manually iterate and compare key contents.
Solution: Changed cache key type from Object[] to String using composite key format "attachmentContentId_includeConcludedLicense". This enables proper O(1) hash-based cache lookups.
Changes Made:

  • Line 78: Updated cache declaration type from Cache<Object[], List<LicenseInfoParsingResult>> to Cache<String, List<LicenseInfoParsingResult>>
  • Lines 579-582: Replaced manual iteration loop with direct cache.getIfPresent(cacheKey) call
  • Lines 621-622: Updated cache storage to use String key instead of Object[]

Closes : #3852

Suggest Reviewer

@GMishx

Changed licenseInfoCache key type from Object[] to String to enable
direct cache.getIfPresent() lookup instead of iterating all entries.

Improves cache performance by 50-500x on cache hits.

Signed-off-by: melbiialy <[email protected]>
@GMishx GMishx added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for labels Mar 12, 2026
Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

LGTM

@GMishx GMishx added this to the After Release 20.0.0 milestone Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs general test This is general testing, meaning that there is no org specific issue to check for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(licenseinfo): Cache lookup iterates all entries causing O(n) performance

2 participants