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

refactor(parser): reduce Token size from 32 to 16 bytes #1962

Merged
merged 1 commit into from
Jan 9, 2024
Merged

Conversation

Boshen
Copy link
Member

@Boshen Boshen commented Jan 9, 2024

Part of #1880

Token size is reduced from 32 to 16 bytes by changing the previous
token value Option<&'a str> to a u32 index handle.

It would be nice if this handle is eliminated entirely because
the normal case for a string is always &source_text[token.span.start.token.span.end]

Unfortunately, JavaScript allows escaped characters to appear in
identifiers, strings and templates. These strings need to be unescaped
for equality checks, i.e. "\a" === "a".

This leads us to adding a escaped_strings[] vec for storing these unescaped and allocated
strings.

Performance regression for adding this vec should be minimal because escaped strings are rare.

Background Reading:

Copy link
Member Author

Boshen commented Jan 9, 2024

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

Join @Boshen and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added the A-parser Area - Parser label Jan 9, 2024
Copy link

codspeed-hq bot commented Jan 9, 2024

CodSpeed Performance Report

Merging #1962 will improve performances by 8.76%

Comparing 01-08-wip (24cfd1b) with main (66e95a5)

Summary

⚡ 1 improvements
✅ 13 untouched benchmarks

Benchmarks breakdown

Benchmark main 01-08-wip Change
semantic[pdf.mjs] 123.1 ms 113.2 ms +8.76%

Part of #1880

`Token` size is from 32 to 16 bytes by changing the previous
token value `Option<&'a str>` to a u32 index handle.

It would be nice if this handle is eliminated entirely because
the normal case for a string is always `source_text[token.span.start.token.span.end]`

Unfortunately, JavaScript allows escaped characters to appear in
identifiers, strings and templates. These strings need to be unescaped
for equality checks, i.e. `"\a"  === "a"`.

This leads us to adding a `escaped_strings` `vec` for storing these unescaped and allocated
strings.

Performance regression for adding this vec should be minimal because escaped strings are rare.

Background Reading:

* https://floooh.github.io/2018/06/17/handles-vs-pointers.html
@Boshen
Copy link
Member Author

Boshen commented Jan 9, 2024

image

@overlookmotel I think this is the furthest I can go 😅

@Boshen Boshen merged commit 4706765 into main Jan 9, 2024
18 checks passed
@Boshen Boshen deleted the 01-08-wip branch January 9, 2024 07:17
IWANABETHATGUY pushed a commit to IWANABETHATGUY/oxc that referenced this pull request May 29, 2024
…t#1962)

Part of oxc-project#1880

`Token` size is reduced from 32 to 16 bytes by changing the previous
token value `Option<&'a str>` to a u32 index handle.

It would be nice if this handle is eliminated entirely because
the normal case for a string is always
`&source_text[token.span.start.token.span.end]`

Unfortunately, JavaScript allows escaped characters to appear in
identifiers, strings and templates. These strings need to be unescaped
for equality checks, i.e. `"\a"  === "a"`.

This leads us to adding a `escaped_strings[]` vec for storing these
unescaped and allocated
strings.

Performance regression for adding this vec should be minimal because
escaped strings are rare.

Background Reading:

* https://floooh.github.io/2018/06/17/handles-vs-pointers.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area - Parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant