How we sped up ranking factor computation in Ozon search with dynamic compilation

Pyotr Portnov29 May 2026

Problem

Ozon's mid-search layer ranks a few thousand candidate products per query. For one query it computes hundreds of interdependent features, many of them "calculated" formulas over other features (price, rating, delivery time, weights), written by data scientists in a DSL and reloaded every couple of hours. Some formulas nest more than a hundred levels deep. The engine interpreted each formula as a tree of objects with virtual calls, and an intermediate array per operation. Formula evaluation took more than 15% of the service's CPU and about 18% of its allocations.

Example from the article: a formula such as f_qux=f_foo/(f_bar+f_baz) became one BinaryOperator object per node, each allocating its own result array.

Solution in brief

Compile each formula once, when it arrives, into JVM bytecode that is a plain loop over arrays with no recursion. HotSpot can then inline and auto-vectorize it. The team validated the engine with property-based and snapshot tests and a three-step production rollout.

Questions this case answers
  • How to cut the compute and allocation cost of evaluating many frequently changing, user-defined formulas on every request under a latency budget
  • How to replace a scoring engine in production and prove that its outputs stay identical to the old one
  • How to cut the CPU cost of evaluating hundreds of ranking formulas per search query
  • How to evaluate formulas written by data scientists in a DSL without hand-porting each one to code

Tools and methods

  • OW2 ASM — generates the bytecode for each formula.
  • JMH — microbenchmarks for every hypothesis before it goes into the compiler.
  • async-profiler — CPU and allocation flamegraphs in production.
  • Fernflower / Vineflower, hsdis, Compiler Explorer — decompile the generated classes and inspect JIT assembly.
  • Property-based and snapshot tests — check that compiled results match the old engine.
  • Shadow mode — runs the new engine next to the old one before switching.
Continue reading — it's free

Google or a one-time email code. No password.