TreeWalker: How Partial Evaluation Speeds Up Grouped Tree-Ensemble Inference
Shopify engineers describe TreeWalker, an open-source Rust engine that applies partial evaluation to tree-ensemble scoring: it resolves shared-feature decisions once per group of related rows using bit-vector masks, achieving 3.96× faster delivery-model evaluation in internal tests and up to 9.1× on public survival datasets at 128-row groups, while acknowledging that setup costs can outweigh savings in small or highly varied groups.
When a tree ensemble scores multiple related rows—say, twelve candidate delivery dates for the same package—most of the decisions are identical across those rows. The carrier, weight, and destination do not change; only the horizon and calendar features vary. Yet conventional inference walks every tree independently for every row, repeating the same comparisons hundreds of times.
Shopify engineers Richard Newman and Durmus Karatay built TreeWalker to exploit this redundancy. Their open-source Rust engine applies partial evaluation to grouped tree-ensemble inference: it identifies features that are constant across a group of rows, resolves the matching tree decisions once, and reuses those results for every row in the group. For features that do vary, it precomputes predicate masks by sorting values once per feature and sweeping distinct thresholds, so that a question repeated across hundreds of trees reuses the same prepared answer.
The mechanism relies on a row mask—a bit vector recording which rows remain active at each node. When a split divides the group, TreeWalker intersects the active mask with the prepared predicate mask to select matching rows, and the remaining rows take the other branch. Original row positions stay intact, so each row retains its own running total. When all rows in a subset answer the same way at a node, TreeWalker skips the empty sibling and continues without a recursive call—an optimization the authors call the unsplit shortcut.