Skip to content

fix(codegen): escape </script #11782

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

Merged
merged 2 commits into from
Jul 2, 2025

Conversation

xu-cheng
Copy link
Contributor

@xu-cheng xu-cheng commented Jun 17, 2025

Fixes #10334.

Replace #10340 to cover the escape for both template literals and comments. We don’t need to handle regex, which is already covered by existing codegen.

Please let me know anything needed to merge this PR. Thanks.

Copy link
Contributor

graphite-app bot commented Jun 17, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-codegen Area - Code Generation C-bug Category - Bug labels Jun 17, 2025
@Boshen Boshen requested a review from overlookmotel June 18, 2025 04:01
@xu-cheng xu-cheng force-pushed the codgen_escape_script branch 3 times, most recently from 8d800f6 to 47c7866 Compare June 18, 2025 20:49
@overlookmotel
Copy link
Contributor

Thanks very much for doing this! I'm tied up next few days, but will endeavor to review (and hopefully merge) early next week.

Copy link

codspeed-hq bot commented Jun 20, 2025

CodSpeed Instrumentation Performance Report

Merging #11782 will improve performances by 13.32%

Comparing xu-cheng:codgen_escape_script (1e860a2) with main (ff1d42f)

Summary

⚡ 1 improvements
✅ 37 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.1 ms 2.7 ms +13.32%

@xu-cheng xu-cheng force-pushed the codgen_escape_script branch from 47c7866 to 5a2a3a9 Compare June 24, 2025 23:50
@xu-cheng xu-cheng force-pushed the codgen_escape_script branch 3 times, most recently from 7865eef to 3223051 Compare June 25, 2025 04:37
@xu-cheng xu-cheng force-pushed the codgen_escape_script branch from 3223051 to 922f770 Compare June 25, 2025 04:42
@xu-cheng xu-cheng requested a review from overlookmotel June 25, 2025 17:38
@overlookmotel overlookmotel force-pushed the codgen_escape_script branch from 922f770 to 1e860a2 Compare July 2, 2025 17:03
Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Thank you!

-2% on codegen benchmarks, which isn't surprising given the extra checks. I'll try to optimize it a little in a follow-up.

Comment on lines +729 to +737
// Compiler condenses these operations to an 8-byte read, u64 AND, and u64 compare.
// https://godbolt.org/z/oGG16fK6v
let mut slice: [u8; 8] = slice.try_into().unwrap();
for b in slice.iter_mut().skip(2) {
// `| 32` converts ASCII upper case letters to lower case.
*b |= 32;
}

slice == *b"</script"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! You shaved a branch off my version.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jul 2, 2025
Copy link
Contributor

graphite-app bot commented Jul 2, 2025

Merge activity

  • Jul 2, 5:09 PM UTC: @xu-cheng we removed the merge queue label because we could not find a Graphite account associated with your GitHub profile.

You must have a Graphite account in order to use the merge queue. Create an account and try again using this link

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jul 2, 2025
@overlookmotel overlookmotel merged commit 22799c3 into oxc-project:main Jul 2, 2025
24 checks passed
@xu-cheng xu-cheng deleted the codgen_escape_script branch July 2, 2025 17:28
graphite-app bot pushed a commit that referenced this pull request Jul 2, 2025
Follow-on after #11782. Clarify comments.
graphite-app bot pushed a commit that referenced this pull request Jul 2, 2025
Follow-on after #11782. Add `#[inline(always)]` to `is_script_close_tag`, to ensure compiler can deduce the slice is 8 bytes long, and remove a branch.
graphite-app bot pushed a commit that referenced this pull request Jul 3, 2025
Follow-on after #11782. That PR fixed escaping `</script` in strings, but it regressed some codegen benchmarks by 2%.

Optimize the string search to win some of that perf back by:

1. Doing a preliminary search for `<` first, and only the more expensive search for `</script` once a `<` is found.
2. Searching longer strings for `<` in chunks of 16 bytes, using SIMD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codegen: escape </script
2 participants