Skip to content

perf(tree): Lazily initialize event buffer#27382

Merged
Josmithr merged 7 commits into
microsoft:mainfrom
Josmithr:tree/lazy-event-buffer
May 21, 2026
Merged

perf(tree): Lazily initialize event buffer#27382
Josmithr merged 7 commits into
microsoft:mainfrom
Josmithr:tree/lazy-event-buffer

Conversation

@Josmithr
Copy link
Copy Markdown
Contributor

Most nodes likely don't get any event subscriptions. Lazy initialization avoids unnecessary allocations and internal event registrations..

Copilot AI review requested due to automatic review settings May 21, 2026 22:38
@Josmithr Josmithr requested a review from a team as a code owner May 21, 2026 22:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (87 lines, 2 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

Copy link
Copy Markdown
Contributor

@noencke noencke left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 simple-tree node event handling by lazily allocating the per-node kernel event buffer, reducing allocations and internal event wiring for nodes that never receive event subscriptions.

Changes:

  • Lazily initialize TreeNodeKernel’s internal KernelEventBuffer on first access to kernel.events, and migrate the source on hydration only if the buffer exists.
  • Add runtime protection against subscribing on a disposed event buffer.
  • Extend treeNodeKernel tests to cover hydration with pre-registered listeners, disposed-node subscription behavior, and subscribe/unsubscribe behavior within withBufferedTreeEvents.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/dds/tree/src/test/simple-tree/core/treeNodeKernel.spec.ts Adds regression tests covering lazy buffer allocation edge cases across hydration, disposal, and buffered scopes.
packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Implements lazy KernelEventBuffer creation and conditional migration/disposal logic; adds an assertion guarding event registration on disposed buffers.

Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts
Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts
Comment thread packages/dds/tree/src/test/simple-tree/core/treeNodeKernel.spec.ts Outdated
Josmithr and others added 4 commits May 21, 2026 15:51
@Josmithr Josmithr enabled auto-merge (squash) May 21, 2026 23:00
}

public get events(): Listenable<KernelEvents> {
assert(!this.disposed, "Cannot register events on a disposed node");
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.

Why doesn't this also use this.assertNotDisposed()?

@Josmithr Josmithr merged commit 9b0623e into microsoft:main May 21, 2026
31 checks passed
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.

3 participants