Skip to content

perf(kernel): replace linear method/property search with Map lookup#5056

Merged
mergify[bot] merged 4 commits intoaws:mainfrom
awsmadi:perf/kernel-method-property-map
Apr 10, 2026
Merged

perf(kernel): replace linear method/property search with Map lookup#5056
mergify[bot] merged 4 commits intoaws:mainfrom
awsmadi:perf/kernel-method-property-map

Conversation

@awsmadi
Copy link
Copy Markdown
Contributor

@awsmadi awsmadi commented Mar 10, 2026

Summary

  • Replace O(n) linear search through method/property arrays with O(1) Map lookups
  • Lazy Map construction on first access per type FQN
  • No cache invalidation needed (complementary to type cache PR)

Motivation

#tryTypeInfoForMethod() and #tryTypeInfoForProperty() iterate through arrays on every invoke() and get()/set() call: for (const m of methods) { if (m.name === methodName) return m; }. For types with many members (e.g., CfnBucket with 50+ properties), this is measurable overhead.

Changes

  • packages/@jsii/kernel/src/kernel.ts: Add #methodMapCache and #propertyMapCache with lazy Map construction per FQN

Design Notes

  • Cache stores only direct members per FQN — inheritance handled by existing recursion into parent types
  • jsii prohibits method overloading, so names are unique within a type (Map.set won't overwrite)
  • Empty types produce empty Maps; Map.get() returns undefined, correctly falling through to parent recursion

Impact

  • Behavioral parity: Verified — same results as linear search for all cases including inheritance
  • Memory: Bounded by total unique FQNs × average members per type

Test plan

  • Existing kernel tests pass (including inheritance tests)
  • Run full cross-language compliance suite

#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).
mrgrain
mrgrain previously approved these changes Apr 9, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Apr 9, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

Merging (with squash)...

@mergify mergify bot added the queued label Apr 9, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

Merge Queue Status

  • Entered queue2026-04-09 12:04 UTC · Rule: default-squash
  • 🚫 Left the queue2026-04-09 12:04 UTC · at 68f2bce60fe625569d23a403aae9a76225abfb68

This pull request spent 39 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/main.yml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify mergify bot added dequeued and removed queued labels Apr 9, 2026
@mergify mergify bot dismissed mrgrain’s stale review April 9, 2026 12:05

Pull request has been modified.

@mergify mergify bot removed the dequeued label Apr 9, 2026
mrgrain
mrgrain previously approved these changes Apr 9, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

Merging (with squash)...

@mergify mergify bot dismissed mrgrain’s stale review April 9, 2026 13:13

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 10, 2026

Merging (with squash)...

@mergify mergify bot added the queued label Apr 10, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 10, 2026

Merge Queue Status

  • Entered queue2026-04-10 08:14 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-04-10 08:48 UTC · at 3d1a22b2d5ae68b3f8286066d66b19893eee5a0c

This pull request spent 34 minutes 22 seconds in the queue, including 34 minutes 1 second running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • status-success=Integration test (jsii-pacmak)
  • status-success=Unit Tests
  • any of [🛡 GitHub branch protection]:
    • check-success = Integration test (jsii-pacmak)
    • check-neutral = Integration test (jsii-pacmak)
    • check-skipped = Integration test (jsii-pacmak)
  • any of [🛡 GitHub branch protection]:
    • check-success = Build
    • check-neutral = Build
    • check-skipped = Build
  • any of [🛡 GitHub branch protection]:
    • check-success = Unit Tests
    • check-neutral = Unit Tests
    • check-skipped = Unit Tests

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 10, 2026

Merging (with squash)...

@mergify mergify bot merged commit 9df2e30 into aws:main Apr 10, 2026
31 of 32 checks passed
@mergify mergify bot removed pr/ready-to-merge This PR is ready to be merged. queued labels Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants