Skip to content

Enable tuple traversal optimization for multiple selectors#652

Open
preciz wants to merge 2 commits intophilss:mainfrom
preciz:speed_up_multiple_selectors
Open

Enable tuple traversal optimization for multiple selectors#652
preciz wants to merge 2 commits intophilss:mainfrom
preciz:speed_up_multiple_selectors

Conversation

@preciz
Copy link
Contributor

@preciz preciz commented Dec 18, 2025

There is a 3-4x speed up for 2-3 cases "Two classes" and "Three classes" and the memory usage is only 1/4 for those compared to the original.

I also ran the benchs/finder.exs benchmarks and there the "class multiple" cases show the same speed up like the benchmark below.

  html = File.read!("benchs/big.html")
  parsed = Floki.parse_document!(html)

  Benchee.run(
    %{
      "Single class" => fn ->
        Floki.find(parsed, ".class-mw-redirect")
      end,
      "Two classes" => fn ->
        Floki.find(parsed, ".class-mw-redirect, .reference")
      end,
      "Three classes" => fn ->
        Floki.find(parsed, ".class-mw-redirect, .reference, .external")
      end
    },
    time: 10,
    memory_time: 2
  )

@preciz preciz marked this pull request as draft December 18, 2025 11:03
@preciz preciz marked this pull request as ready for review December 18, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant