mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
JsonParser: Cache the last seen string starting with each possible char
Keep a 256-entry string cache during parse to avoid creating some new strings when possible. This cache is far from perfect but very cheap. Since none of the strings are transient, this only costs us a couple of pointers and a bit of ref-count manipulation. The cache hit rate on 4chan_catalog.json is ~33% and the speedup on the load_4chan_catalog benchmark is ~7%.
This commit is contained in:
parent
a8740f82eb
commit
4e004a664f
Notes:
sideshowbarker
2024-07-19 12:54:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4e004a664fb
2 changed files with 14 additions and 1 deletions
|
@ -92,7 +92,18 @@ String JsonParser::consume_quoted_string()
|
|||
}
|
||||
}
|
||||
consume_specific('"');
|
||||
return String::copy(buffer);
|
||||
|
||||
if (buffer.is_empty())
|
||||
return {};
|
||||
|
||||
auto& last_string_starting_with_character = m_last_string_starting_with_character[buffer.first()];
|
||||
if (last_string_starting_with_character.length() == buffer.size()) {
|
||||
if (!memcmp(last_string_starting_with_character.characters(), buffer.data(), buffer.size()))
|
||||
return last_string_starting_with_character;
|
||||
}
|
||||
|
||||
last_string_starting_with_character = String::copy(buffer);
|
||||
return last_string_starting_with_character;
|
||||
}
|
||||
|
||||
JsonObject JsonParser::parse_object()
|
||||
|
|
|
@ -40,6 +40,8 @@ private:
|
|||
|
||||
StringView m_input;
|
||||
int m_index { 0 };
|
||||
|
||||
String m_last_string_starting_with_character[256];
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue