forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original commit message: [fastcall] Implement support for onebyte string arguments This CL adds one byte string specialization support for fast API call arguments. It introduces a kOneByteString variant to CTypeInfo. We see a ~6x improvement in Deno's TextEncoder#encode microbenchmark. Rendered results: https://divy-v8-patches.deno.dev/ Bug: chromium:1052746 Change-Id: I47c3a9e101cd18ddc6ad58f627db3a34231b60f7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4036884 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Maya Lekova <mslekova@chromium.org> Commit-Queue: Maya Lekova <mslekova@chromium.org> Cr-Commit-Position: refs/heads/main@{#84552} Refs: v8/v8@bc831f8 PR-URL: nodejs#45788 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
- Loading branch information
1 parent
811cebe
commit 5b61599
Showing
8 changed files
with
200 additions
and
2 deletions.
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
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()); |