1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

LibRegex: Better estimate the cost of laying out alts as a chain

Previously we were counting the total number of *nodes* in the tree for
the chain cost, which greatly underestimated its cost when large
bytecode entries were present,
This commit switches to estimating it using the total bytecode *size*,
which is a closer value to the true cost than the tree node count.

This corresponds to a ~4x perf improvement on /<script|<style|<link/ in
speedometer.
This commit is contained in:
Ali Mohammad Pur 2025-04-23 14:20:48 +02:00 committed by Andreas Kling
parent 64577ad704
commit 09eb28ee1d
Notes: github-actions[bot] 2025-04-23 20:59:21 +00:00

View file

@ -1264,7 +1264,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
// This is really only worth it if we don't blow up the size by the 2-extra-instruction-per-node scheme, similarly, if no nodes are shared, we're better off not using a tree.
auto tree_cost = (total_nodes - common_hits) * 2;
auto chain_cost = total_nodes + alternatives.size() * 2;
auto chain_cost = total_bytecode_entries_in_tree + alternatives.size() * 2;
dbgln_if(REGEX_DEBUG, "Total nodes: {}, common hits: {} (tree cost = {}, chain cost = {})", total_nodes, common_hits, tree_cost, chain_cost);
if (common_hits == 0 || tree_cost > chain_cost) {