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

Improve regex performance #11635

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Improve regex performance #11635

merged 1 commit into from
Aug 7, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 6, 2024

Changes

Adds the regexp/prefer-regexp-test and regexp/prefer-regexp-exec lint rules, which helps with perf. I've benchmarked it in the past, like in lukeed/polka#210, where preferring regex.exec over string.match is faster.

Testing

Existing tests should pass

Docs

I didn't add a changeset as it's mostly a refactor, but if anyone feels like the changes are a bit big, I'm happy to add a changeset too.

Copy link

changeset-bot bot commented Aug 6, 2024

⚠️ No Changeset found

Latest commit: ddd437d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added feat: markdown Related to Markdown (scope) pkg: vue Related to Vue (scope) pkg: integration Related to any renderer integration (scope) pkg: create-astro Related to the `create-astro` package (scope) pkg: astro Related to the core `astro` package (scope) labels Aug 6, 2024
@ematipico
Copy link
Member

Can you run the benchmark job to see if there's a difference?

@bluwy
Copy link
Member Author

bluwy commented Aug 7, 2024

!bench

Copy link
Contributor

github-actions bot commented Aug 7, 2024

PR Benchmark

Memory

Elapsed time (s) Memory used (MB) Final memory (MB)
SSR build 3.51 27.33 70.04
Client build 0.09 0.42 69.75
Static generate 0.64 8.16 62.10

Render

Page Avg (ms) Stdev (ms) Max (ms)
/astro 122.70 40.94 227.09
/md 3.40 2.53 25.86
/mdx 99.89 21.68 180.27

Server stress

Avg Stdev Max
Latency 3496.69 ms 1080.71 ms 6190 ms
Avg Stdev Min Total in 30s
Req/Sec 270.61 140.8 281 8.1k requests
Bytes/Sec 47.7 MB 24.8 MB 49.5 MB 1.43 GB read

CLI Startup

Command Avg (ms) Stdev (ms) Max (ms)
astro --help 276.03 3.02 279.87
astro info 645.03 4.92 653.31

Main Benchmark

Memory

Elapsed time (s) Memory used (MB) Final memory (MB)
SSR build 3.60 27.50 70.16
Client build 0.09 0.42 69.76
Static generate 0.63 8.16 62.08

Render

Page Avg (ms) Stdev (ms) Max (ms)
/astro 117.68 40.00 222.84
/md 3.23 2.28 25.06
/mdx 102.09 22.99 190.97

Server stress

Avg Stdev Max
Latency 3489.53 ms 1137.15 ms 6400 ms
Avg Stdev Min Total in 30s
Req/Sec 270.9 182.68 100 8.1k requests
Bytes/Sec 47.7 MB 32.2 MB 17.6 MB 1.43 GB read

CLI Startup

Command Avg (ms) Stdev (ms) Max (ms)
astro --help 275.97 4.13 285.18
astro info 653.91 4.72 663.42

@bluwy
Copy link
Member Author

bluwy commented Aug 7, 2024

It seems like there isn't a clear improvement overall, mostly within small fluctuations, but I think it's expected that the regex changes are only prominent at a macro level than from the top level.

@bluwy bluwy merged commit ea82b03 into main Aug 7, 2024
13 checks passed
@bluwy bluwy deleted the improve-regex-performance branch August 7, 2024 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope) pkg: create-astro Related to the `create-astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: vue Related to Vue (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants