mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Optimize std/json string decoding
name old speed new speed delta wuffs_json_decode_1k/clang5 729MB/s ± 1% 1130MB/s ± 0% +54.99% (p=0.000 n=10+10) wuffs_json_decode_21k_formatted/clang5 541MB/s ± 1% 576MB/s ± 1% +6.44% (p=0.000 n=10+10) wuffs_json_decode_26k_compact/clang5 603MB/s ± 0% 873MB/s ± 1% +44.72% (p=0.000 n=9+10) wuffs_json_decode_217k_stringy/clang5 607MB/s ± 0% 727MB/s ± 0% +19.78% (p=0.000 n=10+10) wuffs_json_decode_1k/gcc9 871MB/s ± 0% 1104MB/s ± 1% +26.74% (p=0.000 n=10+10) wuffs_json_decode_21k_formatted/gcc9 641MB/s ± 1% 628MB/s ± 0% -2.03% (p=0.000 n=10+10) wuffs_json_decode_26k_compact/gcc9 746MB/s ± 1% 892MB/s ± 0% +19.54% (p=0.000 n=10+10) wuffs_json_decode_217k_stringy/gcc9 736MB/s ± 1% 724MB/s ± 1% -1.68% (p=0.000 n=9+10)
This commit is contained in:
1 parent
b5662b2906
commit
07110398f1
2 files changed
+57
-7
No files matched your search
@@ -55,6 +55,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
var stack_byte : base.u32[..= (1024 / 32) - 1]
|
||||
var stack_bit : base.u32[..= 31]
|
||||
var match : base.u32[..= 2]
|
||||
var c_by_4 : base.u32
|
||||
var c : base.u8
|
||||
var backslash : base.u8
|
||||
var char : base.u8
|
||||
@@ -190,6 +191,32 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
string_length = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
// As an optimization, consume non-special ASCII 4 bytes at a time.
|
||||
while args.src.available() > 4,
|
||||
inv args.dst.available() > 0,
|
||||
inv args.src.available() > 0,
|
||||
{
|
||||
c_by_4 = args.src.peek_u32le()
|
||||
if 0x00 <> (lut_chars[0xFF & (c_by_4 >> 0)] |
|
||||
lut_chars[0xFF & (c_by_4 >> 8)] |
|
||||
lut_chars[0xFF & (c_by_4 >> 16)] |
|
||||
lut_chars[0xFF & (c_by_4 >> 24)]) {
|
||||
break
|
||||
}
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
if string_length > (0xFFFB - 4) {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0x40_0021,
|
||||
link: 0x3,
|
||||
length: string_length + 4)
|
||||
string_length = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
string_length += 4
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
char = lut_chars[c]
|
||||
|
||||
|
||||
Reference in new issue
Block a user