Skip to content

Commit d2ce8e7

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Remove short input threshold to fall back to native UTF-8 decoder
When decoding a JS array input as UTF-8 we currently fall back to the decoder implemented in Dart when the input is small. When benchmarked with `benchmark_harness`, for one byte array, I get 6.0us when decoded with the Dart decoder, and 5.8us when decoded with JS `TextDecoder`. So it looks like Dart decoder is never faster when the input is a JS array. Remove the threshold and always call JS when the input is a JS array. (This threshold was copied from dart2js, where accessing JS data is less expensive.) Change-Id: I1a34fd1f38718e34a1ff7bac0d7c6178bf6dd469 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405002 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent b93c826 commit d2ce8e7

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

sdk/lib/_internal/wasm/lib/js_string_convert.dart

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,14 @@ JSStringImpl? decodeUtf8JS(
2020
bool allowMalformed,
2121
) {
2222
final length = end - start;
23-
if (length >= _shortInputThreshold) {
24-
final JSAny? decoder = allowMalformed ? _decoderNonFatal : _decoder;
25-
if (decoder != null) {
26-
final arrayRef = codeUnits.toJSArrayExternRef(start, length);
27-
final textDecoderResult = _useTextDecoder(
28-
externRefForJSAny(decoder),
29-
arrayRef,
30-
);
31-
if (textDecoderResult != null) {
32-
return textDecoderResult;
33-
}
34-
}
23+
final JSAny? decoder = allowMalformed ? _decoderNonFatal : _decoder;
24+
if (decoder != null) {
25+
final arrayRef = codeUnits.toJSArrayExternRef(start, length);
26+
return _useTextDecoder(externRefForJSAny(decoder), arrayRef);
3527
}
3628
return null;
3729
}
3830

39-
// Always fall back to the Dart implementation for strings shorter than this
40-
// threshold, as there is a large, constant overhead for using `TextDecoder`.
41-
// TODO(omersa): This is copied from dart2js runtime, make sure the value is
42-
// right for dart2wasm.
43-
const int _shortInputThreshold = 15;
44-
4531
JSStringImpl? _useTextDecoder(
4632
WasmExternRef? decoder,
4733
WasmExternRef? codeUnits,

0 commit comments

Comments
 (0)