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

syntax: ParseDID performance #853

Merged
merged 2 commits into from
Nov 29, 2024
Merged

syntax: ParseDID performance #853

merged 2 commits into from
Nov 29, 2024

Conversation

bnewbold
Copy link
Collaborator

we are apparently burning a bunch of CPU on this regex in prod, so let's bypass for the most common case (valid did:plc).

Would be nice to have a benchmark demonstrating perf gains (or not).

I did some manually testing with the CLI helper and inserted panic() statements to confirm that valid DID PLC stays on fast path, and other DIDs don't.

Feedback welcome if there is a more idiomatic/performant golang way to do this... this is still doing unicode stuff, I assume, and maybe casting to bytes would be faster? though probably doesn't impact the actual hot path much. strings.ContainsAny or strings.ContainsFunc could be used here I guess but 🤷

Goal is to avoid using full regex parsing for this common case.
profiling was showing that ParseDID regex has been burning a lot of CPU
in prod.
Copy link
Collaborator

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

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

Nice

@bnewbold bnewbold merged commit de950cc into main Nov 29, 2024
8 checks passed
@bnewbold bnewbold deleted the bnewbold/parsedid-perf branch November 29, 2024 20:05
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