Skip to content

remove SIMD dep to get less method invalidations - #146

Merged
jakobnissen merged 2 commits into
BioJulia:masterfrom
SimonDanisch:sd/no-simd
Jun 14, 2026
Merged

jakobnissen merged 2 commits into
BioJulia:masterfrom
SimonDanisch:sd/no-simd

Conversation

@SimonDanisch

Copy link
Copy Markdown
Contributor

Remove the SIMD.jl dependency

While looking into Makie method invalidations, SIMD was a big invalidator
(its broad Base operator methods like >(::Union{Bool, Int8, ...}, ::Vec)
invalidate a lot of compiled code in unrelated packages, we traced
multi-second recompilations of an HTTP server to it), and since we depend on
Automa indirectly via MathTeXEngine, it seemed easiest to just remove that
dependency here.

SIMD.jl was only used in generate_simd_loop. It now emits a branch-free,
fixed 32-iteration loop instead, which LLVM auto-vectorizes to the same
vector code. Judged with BenchmarkTools (validator over ~1MB inputs, medians):

SIMD.jl this PR judge
long [a-z]+ runs 13.14 μs 13.24 μs +0.8% (invariant)
4-range set [A-Za-z0-9_]+ 30.29 μs 24.11 μs -20.4% (improvement)

Note: the skip loop now respects --check-bounds=yes (the raw vload
bypassed it), so benchmark with default flags.

Benchmark script

Run with julia bench.jl out.json on master and on this branch, then compare
with judge:

using Automa, BenchmarkTools

ctx = Automa.CodeGenContext(generator = :goto)
code_runs = Automa.generate_code(ctx, Automa.compile(re"([a-z]+,)+"), nothing)
@eval function validate_runs(data)
    $(code_runs)
    return cs == 0
end
code_ranges = Automa.generate_code(ctx, Automa.compile(re"([A-Za-z0-9_]+ )+"), nothing)
@eval function validate_ranges(data)
    $(code_ranges)
    return cs == 0
end

# long skippable runs (best case for the skip loop), and a byte set
# needing several compares per chunk
data_runs = (repeat("a", 10_000) * ",")^100
data_ranges = (repeat("aZ9_", 2500) * " ")^100
@assert validate_runs(data_runs) && validate_ranges(data_ranges)

suite = BenchmarkGroup()
suite["long_runs"] = @benchmarkable validate_runs($data_runs)
suite["multi_range"] = @benchmarkable validate_ranges($data_ranges)
tune!(suite)
BenchmarkTools.save(ARGS[1], run(suite; seconds = 20))
using BenchmarkTools
pr, base = only(BenchmarkTools.load("pr.json")), only(BenchmarkTools.load("master.json"))
judge(median(pr), median(base))

@kescobo

kescobo commented Jun 12, 2026

Copy link
Copy Markdown
Member

Rad, thanks for this! LGTM, but Jakob should probably do the final approval

@jakobnissen

Copy link
Copy Markdown
Member

Super cool, thank you very much. This is indeed much better.

Automa's current SIMD capabilities are the end of a long, bitter journey where I've increasingly scaled back ambitions, and rolled back improvements, as I found out Julia's support for explicit SIMD is not great at the moment. While it's slightly sad to see the SIMD completely disappear, I do agree it's for the better since the current implementation was no better than SIMD produced by the autovectorizer in this PR.

@jakobnissen
jakobnissen merged commit 0eb1921 into BioJulia:master Jun 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants