LibWeb: Cache attribute names in lowercase to speed up selector matching

When matching a CSS attribute selector against an HTML element, the
attribute name is case-insensitive. Before this change, that meant we
had to call equals_ignoring_ascii_case() on all the attribute names.

We now cache the attribute name lowercased on each Attr node, which
allows us to do FlyString-to-FlyString comparison (simple pointer
comparison).

This brings attribute selector matching from 6% to <1% when loading our
GitHub repo at https://github.com/SerenityOS/serenity
This commit is contained in:
Andreas Kling 2024-03-15 18:19:59 +01:00
commit 43ef3dc0ab
Notes: sideshowbarker 2024-07-17 02:06:40 +09:00
5 changed files with 35 additions and 8 deletions

View file

@ -54,6 +54,8 @@ public:
Attr const* remove_attribute(FlyString const& qualified_name);
Attr const* remove_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name);
Attr const* get_attribute_with_lowercase_qualified_name(FlyString const&) const;
private:
explicit NamedNodeMap(Element&);