r/Protos • • 9d ago

Optimizing pattern matching in a Truffle-based language: from 7,448 to 54 compiler graph nodes

I've just completed another major optimization in Protos, an experimental prototype-based programming language built on GraalVM and Truffle Bytecode DSL.

Eligible caseOf and match expressions now compile into guarded branches, with direct primitive comparisons and inlined actions.

In our pre-integration benchmark snapshot, the first primitive-switch workload went from 7,448 to 54 guest Tier-2 graph nodes after TruffleTier.

An interesting discovery was how much the compiler version itself affected the comparison. After aligning Protos and GraalPy on GraalVM 25.5.5.0.3, the integer-switch LowTier comparison became 345 versus 328 nodes.

These are structural measurements, not execution-time speedups.

The optimization preserves ordinary message semantics, custom matching behavior, method overrides and suspension.

Source: https://github.com/guillermomolina/protos

Implementation history: https://github.com/guillermomolina/protos/issues/883

1 Upvotes

0 comments sorted by