Skip to content
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

VSCODE-639: Replace regex fragment matching with streaming KMP #837

Merged
merged 5 commits into from
Oct 24, 2024

Conversation

nirinchev
Copy link
Contributor

@nirinchev nirinchev commented Sep 26, 2024

Description

I got nerd-sniped by #835, and wanted to try out a regex-less implementation of the identifier matching algorithm. I've implemented a stateful streaming Knuth-Morris-Pratt algorithm for the identifier matching and then a stateful matcher for the content. Those could have been trivially combined, but I opted to keep them separate to 1) keep the concerns more cleanly separate and 2) to have the building blocks available in case we need to do a simple substring search in the stream without extracting some content between the identifiers.

While I think this approach is slightly more readable and should (theoretically) be more performant, I don't believe we should try and get it in before the code freeze as it's not fixing an actual bug.

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@alenakhineika
Copy link
Contributor

Love it!! Looking forward to this work being finished and merged 🔥

Base automatically changed from VSCODE-528-mongodb-copilot to main September 30, 2024 15:23
@nirinchev nirinchev changed the title Replace regex fragment matching with streaming KMP VSCODE-639: Replace regex fragment matching with streaming KMP Oct 21, 2024
@nirinchev nirinchev marked this pull request as ready for review October 21, 2024 13:58
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

lgtm! Nice writeup. Called out one behavioral change, but I don't think we need to make any changes to accommodate. This is already improving things by making the streaming not block until the whole code block is parsed.

// Finish up anything not streamed yet.
if (contentSinceLastIdentifier.length > 0) {
processStreamFragment(contentSinceLastIdentifier);
for await (const fragment of inputIterable) {
Copy link
Member

Choose a reason for hiding this comment

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

One change in behavior that will happen is when a fragment is very large, and could contain two code blocks. It would now print all of the fragment before it adds the actions.
This won't impact our use of this since the fragments are pretty much always 2-4 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting that. The fix for it was simple enough, so I added it anyway just to be on the safe side.

* main:
  VSCODE-640: Adapt message content access to latest vscode API (#857)
  Update changelog (#856)
@nirinchev nirinchev merged commit 10be1c6 into main Oct 24, 2024
5 checks passed
@nirinchev nirinchev deleted the ni/streaming-kmp branch October 24, 2024 09:52
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