WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
221593
[JSC] Make JSON.parse faster by using table for fast string parsing
https://bugs.webkit.org/show_bug.cgi?id=221593
Summary
[JSC] Make JSON.parse faster by using table for fast string parsing
Yusuke Suzuki
Reported
2021-02-08 21:04:08 PST
[JSC] Make JSON.parse faster by using table for fast string parsing
Attachments
Patch
(21.28 KB, patch)
2021-02-08 21:06 PST
,
Yusuke Suzuki
rniwa
: review+
Details
Formatted Diff
Diff
Patch
(16.98 KB, patch)
2021-02-08 21:57 PST
,
Yusuke Suzuki
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2021-02-08 21:06:17 PST
Created
attachment 419674
[details]
Patch
Ryosuke Niwa
Comment 2
2021-02-08 21:26:11 PST
Comment on
attachment 419674
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=419674&action=review
> Source/JavaScriptCore/runtime/LiteralParser.cpp:437 > +enum StringCharacter : uint8_t { Slow, Fast, }; > +static constexpr const StringCharacter safeStringLatin1CharactersInStrictJSON[256] = {
What does slow & fast mean? StringCharacter is also a very generic term to use here. Maybe renaming this to safeLatin1CharacterInStrictJSON and using boolean would be better. If we wanted to use enum class maybe something like this will be more appropriate: enum class JSONLiteralCharacterType : uint8_t { Safe, NotSafeInStrictMode };
> Source/JavaScriptCore/runtime/LiteralParser.cpp:839 > + return (c >= ' ' && c != '\\' && c != terminator) || (c == '\t');
Isn't this really just safeStringLatin1CharactersInStrictJSON[c] == StringCharacter::Fast || c == '\t'?
> Source/JavaScriptCore/runtime/LiteralParser.cpp:850 > + return (c >= ' ' && isLatin1(c) && c != '\\' && c != terminator) || (c == '\t');
Ditto.
Geoffrey Garen
Comment 3
2021-02-08 21:27:49 PST
r=me
> Source/JavaScriptCore/runtime/LiteralParser.cpp:438 > +// 256 Latin-1 codes > +enum StringCharacter : uint8_t { Slow, Fast, }; > +static constexpr const StringCharacter safeStringLatin1CharactersInStrictJSON[256] = { > +/* 0 - Null */ StringCharacter::Slow,
I'm curious: Why do we call these 'Fast' and 'Slow' instead of 'Safe' and 'Unsafe'? I'm not familiar with this distinction -- I'm just observing that the table name is "safe..." and not "fast....".
> Source/JavaScriptCore/runtime/LiteralParser.cpp:837 > + if constexpr (set == SafeStringCharacterSet::Strict) > + return safeStringLatin1CharactersInStrictJSON[c] == StringCharacter::Fast;
Can we make the table store booleans, so we can just return the boolean instead of doing an additional comparison against StringCharacter::Fast? (Alternatively, I suppose we could change the return value from bool to StringCharacter.)
Yusuke Suzuki
Comment 4
2021-02-08 21:31:14 PST
Comment on
attachment 419674
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=419674&action=review
>> Source/JavaScriptCore/runtime/LiteralParser.cpp:437 >> +static constexpr const StringCharacter safeStringLatin1CharactersInStrictJSON[256] = { > > What does slow & fast mean? StringCharacter is also a very generic term to use here. > Maybe renaming this to safeLatin1CharacterInStrictJSON and using boolean would be better. > If we wanted to use enum class maybe something like this will be more appropriate: > enum class JSONLiteralCharacterType : uint8_t { Safe, NotSafeInStrictMode };
OK, I'll just change this to boolean.
>> Source/JavaScriptCore/runtime/LiteralParser.cpp:839 >> + return (c >= ' ' && c != '\\' && c != terminator) || (c == '\t'); > > Isn't this really just safeStringLatin1CharactersInStrictJSON[c] == StringCharacter::Fast || c == '\t'?
terminator can be different in non-Strict-JSON (JSONP etc., not an actual JSON case). So still this is a bit different.
>> Source/JavaScriptCore/runtime/LiteralParser.cpp:850 >> + return (c >= ' ' && isLatin1(c) && c != '\\' && c != terminator) || (c == '\t'); > > Ditto.
Changed.
Yusuke Suzuki
Comment 5
2021-02-08 21:57:55 PST
Created
attachment 419676
[details]
Patch
Yusuke Suzuki
Comment 6
2021-02-09 02:01:07 PST
animations/keyframe-pseudo-shadow.html is unrelated.
Yusuke Suzuki
Comment 7
2021-02-09 02:02:19 PST
Committed
r272570
: <
https://trac.webkit.org/changeset/272570
>
Radar WebKit Bug Importer
Comment 8
2021-02-09 02:03:14 PST
<
rdar://problem/74134694
>
Yusuke Suzuki
Comment 9
2021-02-15 02:54:42 PST
8% improvement in JetStream2/json-parse-inspector
Ryosuke Niwa
Comment 10
2021-02-15 14:44:56 PST
(In reply to Yusuke Suzuki from
comment #9
)
> 8% improvement in JetStream2/json-parse-inspector
Nice!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug