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:
parent
64577ad704
commit
09eb28ee1d
Notes:
github-actions[bot]
2025-04-23 20:59:21 +00:00
Author: https://github.com/alimpfard
Commit: 09eb28ee1d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4441
1 changed files with 1 additions and 1 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue