Skip to content

Avoid recursion when collecting prefix tree node values #3401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Apr 18, 2025

Motivation

I noticed we were using recursion to accumulate all of the values in a prefix tree node and its children. Recursion can be quite slow, so I took a stab at removing it with a queue mechanism.

Implementation

The idea is to accumulate nodes in the queue and then pop one by one, adding to the result when appropriate.

On my benchmarks with a small sized tree, this approach is 2x faster than using recursion.

Note: we now push the values into the result in a slightly different order. I updated the tests to match. Notice that this makes no difference for our usages for completion since the editor is expected to sort the entries based on the sortText property.

@vinistock vinistock added server This pull request should be included in the server gem's release notes other Changes that aren't bugfixes, enhancements or breaking changes labels Apr 18, 2025 — with Graphite App
Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock self-assigned this Apr 18, 2025
@vinistock vinistock marked this pull request as ready for review April 18, 2025 00:46
@vinistock vinistock requested a review from a team as a code owner April 18, 2025 00:46
@vinistock vinistock enabled auto-merge (squash) April 18, 2025 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
other Changes that aren't bugfixes, enhancements or breaking changes server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant