perf(kernel): replace linear method/property search with Map lookup#5056
perf(kernel): replace linear method/property search with Map lookup#5056mergify[bot] merged 4 commits intoaws:mainfrom
Conversation
#tryTypeInfoForMethod() and #tryTypeInfoForProperty() performed O(n) linear searches through method/property arrays on every invocation and property access. Build name-indexed Maps lazily per type for O(1) lookups. Estimated improvement for classes with many members (e.g., CfnBucket with 50+ properties).
|
Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it! |
|
Merging (with squash)... |
Merge Queue Status
This pull request spent 39 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. |
|
Merging (with squash)... |
|
Merging (with squash)... |
Merge Queue Status
This pull request spent 34 minutes 22 seconds in the queue, including 34 minutes 1 second running CI. Required conditions to merge
|
|
Merging (with squash)... |
Summary
Motivation
#tryTypeInfoForMethod()and#tryTypeInfoForProperty()iterate through arrays on everyinvoke()andget()/set()call:for (const m of methods) { if (m.name === methodName) return m; }. For types with many members (e.g.,CfnBucketwith 50+ properties), this is measurable overhead.Changes
packages/@jsii/kernel/src/kernel.ts: Add#methodMapCacheand#propertyMapCachewith lazy Map construction per FQNDesign Notes
Map.get()returnsundefined, correctly falling through to parent recursionImpact
Test plan