Skip to content

encoding: remove double encoding validation on fatal path#63587

Open
araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:string-bytes-encode-validated-utf8
Open

encoding: remove double encoding validation on fatal path#63587
araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:string-bytes-encode-validated-utf8

Conversation

@araujogui
Copy link
Copy Markdown
Member

@araujogui araujogui commented May 26, 2026

Create StringBytes::EncodeValidatedUTF8 to avoid double UTF-8 validation on fatal path

Copilot AI review requested due to automatic review settings May 26, 2026 17:30
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels May 26, 2026
@araujogui araujogui force-pushed the string-bytes-encode-validated-utf8 branch from 92897bc to a2ccfb5 Compare May 26, 2026 17:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR optimizes UTF-8 decoding in the encoding binding by avoiding redundant UTF-8 validation when input has already been validated.

Changes:

  • Added StringBytes::EncodeValidatedUTF8() API for encoding already-validated UTF-8.
  • Refactored the fast UTF-8→UTF-16 conversion into a shared helper (EncodeKnownValidNonAsciiUTF8).
  • Updated BindingData::DecodeUTF8() to use the new API after performing UTF-8 validation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/string_bytes.h Declares a new EncodeValidatedUTF8() entry point for already-validated UTF-8.
src/string_bytes.cc Implements EncodeValidatedUTF8() and factors out the fast conversion helper used by both code paths.
src/encoding_binding.cc Uses EncodeValidatedUTF8() after explicit UTF-8 validation to avoid re-validation overhead.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/string_bytes.h
Comment thread src/string_bytes.cc Outdated
Comment thread src/string_bytes.cc
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

❌ Patch coverage is 68.96552% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.31%. Comparing base (49dcaa0) to head (727b683).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/string_bytes.cc 65.21% 4 Missing and 4 partials ⚠️
src/encoding_binding.cc 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63587      +/-   ##
==========================================
- Coverage   90.33%   90.31%   -0.03%     
==========================================
  Files         730      730              
  Lines      234362   234671     +309     
  Branches    43906    43946      +40     
==========================================
+ Hits       211713   211941     +228     
- Misses      14371    14450      +79     
- Partials     8278     8280       +2     
Files with missing lines Coverage Δ
src/string_bytes.h 80.00% <ø> (ø)
src/encoding_binding.cc 53.35% <83.33%> (+0.43%) ⬆️
src/string_bytes.cc 74.43% <65.21%> (-0.20%) ⬇️

... and 49 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

araujogui added 2 commits May 26, 2026 16:39
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui araujogui force-pushed the string-bytes-encode-validated-utf8 branch from 71e12c1 to 727b683 Compare May 26, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants