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

Faster readRegexp #13453

Merged
merged 5 commits into from Jun 10, 2021
Merged

Faster readRegexp #13453

merged 5 commits into from Jun 10, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jun 10, 2021

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Scanning Regexp is now 200% faster for large regexp, 15% faster for a small regexp with all available flags.

The following improvements are implemented:

  1. avoid single-byte string comparison
  2. avoid codepoint => string conversion by replacing charAt to charCodeAt
  3. avoid update pos to parser state until we have to
  4. avoid reading string twice (String#charCodeAt, String#charAt).

For benchmark results, please check commit messages below.

baseline 256-size RegExp literal : 66124 ops/sec ±8.34% (0.015ms)
baseline 512-size RegExp literal : 43351 ops/sec ±1.05% (0.023ms)
baseline 1024-size RegExp literal : 24620 ops/sec ±0.34% (0.041ms)
baseline 2048-size RegExp literal : 12957 ops/sec ±0.2% (0.077ms)
current 256-size RegExp literal : 151662 ops/sec ±12.21% (0.007ms)
current 512-size RegExp literal : 113828 ops/sec ±0.37% (0.009ms)
current 1024-size RegExp literal : 67246 ops/sec ±1.95% (0.015ms)
current 2048-size RegExp literal : 35645 ops/sec ±1.69% (0.028ms)
baseline 256-size RegExp literal : 142419 ops/sec ±14.37% (0.007ms)
baseline 512-size RegExp literal : 110003 ops/sec ±0.95% (0.009ms)
baseline 1024-size RegExp literal : 69509 ops/sec ±0.68% (0.014ms)
baseline 2048-size RegExp literal : 36217 ops/sec ±4.63% (0.028ms)
current 256-size RegExp literal : 166167 ops/sec ±1.04% (0.006ms)
current 512-size RegExp literal : 120889 ops/sec ±1.25% (0.008ms)
current 1024-size RegExp literal : 76181 ops/sec ±1.46% (0.013ms)
current 2048-size RegExp literal : 44898 ops/sec ±1.25% (0.022ms)
baseline 256 small regexp literal with all flags: 4342 ops/sec ±1.57% (0.23ms)
baseline 512 small regexp literal with all flags: 2213 ops/sec ±1.51% (0.452ms)
baseline 1024 small regexp literal with all flags: 1144 ops/sec ±0.22% (0.874ms)
baseline 2048 small regexp literal with all flags: 541 ops/sec ±1.12% (1.849ms)
current 256 small regexp literal with all flags: 4643 ops/sec ±1.3% (0.215ms)
current 512 small regexp literal with all flags: 2355 ops/sec ±1.14% (0.425ms)
current 1024 small regexp literal with all flags: 1176 ops/sec ±0.87% (0.85ms)
current 2048 small regexp literal with all flags: 553 ops/sec ±1.31% (1.807ms)
@JLHwung JLHwung added pkg: parser PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories labels Jun 10, 2021
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46811/

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f377065:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@JLHwung JLHwung merged commit 6c8b233 into babel:main Jun 10, 2021
@JLHwung JLHwung deleted the faster-read-regexp branch June 10, 2021 23:00
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants