1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

LibWeb: Stop putting the FormattingState nodes in a slow hash map

Instead, put them in a Vector<OwnPtr<NodeState>>. Each layout node
has a unique index into the vector. It's a simple serial ID assigned
during layout tree construction. Every new layout restarts the sequence
at 0 for the next ICB.

This is a huge layout speed improvement on all content.
This commit is contained in:
Andreas Kling 2022-07-11 17:12:58 +02:00
parent f6a97ff7d5
commit 0cacaf025d
6 changed files with 45 additions and 45 deletions

View file

@ -30,6 +30,7 @@ struct FormattingState {
: m_parent(parent)
, m_root(find_root())
{
nodes.resize(m_root.nodes.size());
}
FormattingState const& find_root() const
@ -41,6 +42,8 @@ struct FormattingState {
}
struct NodeState {
Layout::NodeWithStyleAndBoxModelMetrics* node { nullptr };
float content_width { 0 };
float content_height { 0 };
Gfx::FloatPoint offset;
@ -106,7 +109,7 @@ struct FormattingState {
// NOTE: get() will not CoW the NodeState.
NodeState const& get(NodeWithStyleAndBoxModelMetrics const&) const;
HashMap<NodeWithStyleAndBoxModelMetrics const*, NonnullOwnPtr<NodeState>> nodes;
Vector<OwnPtr<NodeState>> nodes;
// We cache intrinsic sizes once determined, as they will not change over the course of a full layout.
// This avoids computing them several times while performing flex layout.
@ -123,13 +126,6 @@ struct FormattingState {
FormattingState const* m_parent { nullptr };
FormattingState const& m_root;
struct LookupCache {
NodeWithStyleAndBoxModelMetrics const* box { nullptr };
NodeState* state { nullptr };
bool is_mutable { false };
};
LookupCache m_lookup_cache;
};
Gfx::FloatRect absolute_content_rect(Box const&, FormattingState const&);