-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
src: add fast path to TextEncoder.encodeInto #45701
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2022 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// This file excercises one byte string support for fast API calls. | ||
|
||
// Flags: --turbo-fast-api-calls --expose-fast-api --allow-natives-syntax --turbofan | ||
// --always-turbofan is disabled because we rely on particular feedback for | ||
// optimizing to the fastest path. | ||
// Flags: --no-always-turbofan | ||
// The test relies on optimizing/deoptimizing at predictable moments, so | ||
// it's not suitable for deoptimization fuzzing. | ||
// Flags: --deopt-every-n-times=0 | ||
|
||
assertThrows(() => d8.test.FastCAPI()); | ||
const fast_c_api = new d8.test.FastCAPI(); | ||
|
||
function assertSlowCall(input) { | ||
assertEquals(new Uint8Array(input.length), copy_string(false, input)); | ||
} | ||
|
||
function assertFastCall(input) { | ||
const bytes = Uint8Array.from(input, c => c.charCodeAt(0)); | ||
assertEquals(bytes, copy_string(false, input)); | ||
} | ||
|
||
function copy_string(should_fallback = false, input) { | ||
const buffer = new Uint8Array(input.length); | ||
fast_c_api.copy_string(should_fallback, input, buffer); | ||
return buffer; | ||
} | ||
|
||
%PrepareFunctionForOptimization(copy_string); | ||
assertSlowCall('Hello'); | ||
%OptimizeFunctionOnNextCall(copy_string); | ||
|
||
fast_c_api.reset_counts(); | ||
assertFastCall('Hello'); | ||
assertFastCall(''); | ||
assertFastCall(['Hello', 'World'].join('')); | ||
assertOptimized(copy_string); | ||
assertEquals(3, fast_c_api.fast_call_count()); | ||
assertEquals(0, fast_c_api.slow_call_count()); | ||
|
||
// Fall back for twobyte strings. | ||
fast_c_api.reset_counts(); | ||
assertSlowCall('Hello\u{10000}'); | ||
assertSlowCall('नमस्ते'); | ||
assertSlowCall(['नमस्ते', 'World'].join('')); | ||
assertOptimized(copy_string); | ||
assertEquals(0, fast_c_api.fast_call_count()); | ||
assertEquals(3, fast_c_api.slow_call_count()); | ||
|
||
// Fall back for cons strings. | ||
function getTwoByteString() { | ||
return '\u1234t'; | ||
} | ||
function getCons() { | ||
return 'hello' + getTwoByteString() | ||
} | ||
|
||
fast_c_api.reset_counts(); | ||
assertSlowCall(getCons()); | ||
assertOptimized(copy_string); | ||
assertEquals(0, fast_c_api.fast_call_count()); | ||
assertEquals(1, fast_c_api.slow_call_count()); | ||
|
||
// Fall back for sliced strings. | ||
fast_c_api.reset_counts(); | ||
function getSliced() { | ||
return getCons().slice(1); | ||
} | ||
assertSlowCall(getSliced()); | ||
assertOptimized(copy_string); | ||
assertEquals(0, fast_c_api.fast_call_count()); | ||
assertEquals(1, fast_c_api.slow_call_count()); | ||
|
||
// Fall back for SMI and non-string inputs. | ||
fast_c_api.reset_counts(); | ||
assertSlowCall(1); | ||
assertSlowCall({}); | ||
assertSlowCall(new Uint8Array(1)); | ||
assertEquals(0, fast_c_api.fast_call_count()); | ||
assertEquals(3, fast_c_api.slow_call_count()); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we already have so many files dealing with encodings, does this really need to be a new one (instead of, e.g., staying in
node_buffer
or maybestring_bytes
)? And if so, is this the encoding file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t have any specific thoughts on this. I’ll try to move the encode utf8 to the node_encoding once this is implementation improves the existing benchmark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure why this is a new file when it only covers a tiny part of all encoding-related routines.