Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Datadog Engineering 12 min read Case study hardMaster

How we built a Ruby library that saves 50% in testing time

Datadog built a Ruby test impact analysis library for its Intelligent Test Runner that maps each test to the source files it executes, so tests unrelated to a commit's changed files can be skipped, cutting testing time roughly in half. Ruby's Coverage module (up to 300% overhead, conflicts with simplecov) and TracePoint (~200–400%) were too slow. A C extension hooking RUBY_EVENT_LINE got overhead to 60–80%, and further gains came from rb_profile_frames to avoid string copies and from caching the rb_sourcefile pointer to skip repeated prefix checks. Code-less classes such as Active Record models emit no line events, so a small allocation profiler on RUBY_INTERNAL_EVENT_NEWOBJ adds the source files of instantiated classes. External services, processes and data files remain untracked and are handled through tracked-file lists and unskippable tests.

Assumes: Ruby C extensionscode coverage toolsCI pipelines

Related posts

  • GitHub Does My Operations Homework: A Ruby Speed Story

    Shopify Engineering mediumAdept

    Shopify's YJIT team runs a continuously updated public benchmark site, speed.yjit.org, that reports YJIT as 20.6% faster than interpreted CRuby and 17.4% faster than MJIT overall, and 18.5% faster than CRuby on Railsbench. The setup is low-maintenance: GitHub Actions runs a cron job that SSHes into an AWS instance to run the benchmarks, then commits the results to a Jekyll site hosted on GitHub Pages, and automatically files an issue if any benchmark slows down too much. The write-up covers the practical snags along the way, including Jekyll's _includes and collections constraints, SSH host-key problems caused by AWS reusing IPs, and passing environment variables over SSH. It also compares D3 generated from Erb, raw SVG and matplotlib for producing the graphs.

  • Try Out YJIT for Faster Rubying

    Shopify Engineering mediumAdept

    YJIT, Shopify's just-in-time compiler built into CRuby and slated for Ruby 3.1, compiles frequently used Ruby code to native machine code, speeding up a simple Rails benchmark by 20% or more and a real Shopify web service by about 6% on canary traffic. Building it is the same as building CRuby from source: autoconf 2.69, OpenSSL 1.1 and a C toolchain, then enabling it with --enable-yjit or RUBY_YJIT_ENABLE=1. Compiling with YJIT_STATS or RUBY_DEBUG exposes detailed runtime statistics such as the share of instructions YJIT executed, generated code size and ISEQs compiled. YJIT passes Shopify's and GitHub's unit test suites but is still early, so the team asks users to report crashes and performance results.

  • YJIT: Building a New JIT Compiler for CRuby

    Shopify Engineering easyNovice

    YJIT is a new JIT compiler built inside CRuby by Shopify and GitHub engineers, based on Basic Block Versioning, and aimed at real-world workloads like Rails where the GCC-based MJIT has struggled. After about a year it delivers speedups over the interpreter of 20% on railsbench, 39% on liquid template rendering and 37% on activerecord, with near-peak performance after one iteration. It passes CRuby's ~30,000 tests and the CI suites of Shopify Core and GitHub, and is slated to merge into Ruby 3.1. Only about 79% of railsbench instructions currently run in YJIT, and planned CRuby changes include object shapes, cheaper type tagging, finer-grained constant caching, a lighter calling convention, and rewriting C runtime methods in Ruby to enable inlining.

  • Ruby 3.2’s YJIT is Production-Ready

    Shopify Engineering easyNovice

    YJIT, Shopify's JIT compiler for CRuby, became production-ready in Ruby 3.2 after a port from C99 to Rust and a cut in memory overhead to about a third of Ruby 3.1 levels. The memory savings came from smaller metadata, garbage collection of unused machine code and lazily allocated code pages. YJIT now runs about 38% faster than the 3.2 interpreter on railsbench and supports ARM64. Deployed across Shopify's entire Storefront Renderer, it delivers 5–10% end-to-end request speedups, and its fast compilation suits continuous deployment. Planned work targets memory footprint, faster method calls via a new calling convention and inlining, and a register allocator.

  • How well is ClickHouse tested? A detailed view of increasing our own coverage

    ClickHouse mediumAdept

    ClickHouse's ~2.6M-line C++ codebase reaches 91.8% line, 81.0% branch and 91.8% function coverage, measured with Clang source-based coverage across 23 CI shards every 3 hours and published at coverage.clickhouse.com. Basic blocks, edges and the two Clang instrumentation modes (SanitizerCoverage vs. source-based) are explained, along with the profraw → profdata → llvm-cov pipeline and the continuous-mode trick that keeps profiles from servers that tests kill on purpose. An AI agent in ClickGap finds stable zero-hit gaps and writes guarded, flakiness-checked tests, merging 16 PRs that cover about 5,600 new lines. Per-test line coverage stored in CIDB (about 36B rows) drives test selection, so expensive sanitizer jobs run only the tests that touch changed code.

The quest for software engineering knowledge.

Look:
Layout: