Repository navigation
fix(client): keep String.prototype in fast mode after defining VerbatimString - #3479
Merged
nkaradzhov merged 2 commits intoSep 28, 2026
Merged
Conversation
nkaradzhov
approved these changes
Sep 28, 2026
nkaradzhov
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @Ceereals, great catch! LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request fixes the slowdown of string code that starts as soon as
@redis/clientis loaded on V8.Fixes #3478
class VerbatimString extends StringswitchesString.prototypeto dictionary mode, and method calls on primitive strings never switch it back. One named property store on an object that inherits fromString.prototype, right after the class, restores fast mode. TheVerbatimStringAPI and the decoder do not change.escape-htmlrepro from the issue, Node v26.10.0redisredisloadedredisloaded, with this fixThe new spec loads the client in a fresh
node --allow-natives-syntaxprocess, withrequireand withimport(), and checks%HasFastProperties(String.prototype). It fails without the fix and passes with it on Node 20 and 22.npm test -w @redis/clientpasses exceptSocket reconnectStrategy retry counter is sequential after a post-ready socket loss, which also fails onmasteron my macOS machine.Checklist
npm testpass with this change (including linting)?Note
Low Risk
Localized V8 workaround with no API changes; tests guard against polluting string prototypes.
Overview
Fixes a process-wide V8 performance regression when
@redis/clientloads: definingVerbatimString extends Stringwas puttingString.prototypeinto dictionary (“slow”) mode, which slowed ordinary string operations for the rest of the process.After the class, the PR adds a one-line side-channel store (
Object.create(String.prototype).redisVerbatimString = true) soString.prototypereturns to fast mode without changingVerbatimStringbehavior or RESP decoding.New tests assert
redisVerbatimStringis not visible onString.prototypeorVerbatimStringinstances, and spawn fresh Node processes (CJSrequireand ESMimportof the client) to assert%HasFastProperties(String.prototype)stays true after load.Reviewed by Cursor Bugbot for commit c7c69ae. Bugbot is set up for automated code reviews on this repo. Configure here.