Skip to content

Enable tuple traversal optimization for multiple selectors#652

Merged
philss merged 2 commits into
philss:mainfrom
preciz:speed_up_multiple_selectors
Feb 27, 2026
Merged

Enable tuple traversal optimization for multiple selectors#652
philss merged 2 commits into
philss:mainfrom
preciz:speed_up_multiple_selectors

Conversation

@preciz
Copy link
Copy Markdown
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
@philss philss merged commit 921e932 into philss:main Feb 27, 2026
10 of 12 checks passed
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.

2 participants