---
title: "How we improved APM Java startup by encoding a prefix trie as a JVM constant"
description: "Datadog's Java APM agent filters uninteresting classes by name during JVM startup using ClassNameTrie, a prefix trie encoded entirely in a single string constant and loaded with one ldc instruction."
url: "https://swe.quest/articles/how-we-improved-apm-java-startup-by-encoding-a-prefix-trie-as-a-jvm-constant-ef8ab81cb4120a77"
canonical: "https://www.datadoghq.com/blog/engineering/improving-apm-java-startup-with-a-prefix-trie/"
source: "Datadog Engineering"
published: "2026-08-11"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 11
tags: ["jvm","data-structures","performance","observability","runtimes"]
---

# How we improved APM Java startup by encoding a prefix trie as a JVM constant

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2026-08-11, 11 min read, Deep dive. Original: [https://www.datadoghq.com/blog/engineering/improving-apm-java-startup-with-a-prefix-trie/](https://www.datadoghq.com/blog/engineering/improving-apm-java-startup-with-a-prefix-trie/)

## Summary

Datadog's Java APM agent filters uninteresting classes by name during JVM startup using ClassNameTrie, a prefix trie encoded entirely in a single string constant and loaded with one ldc instruction. That avoids resource I/O, parsing and object construction inside the constrained premain phase, where the JIT is cold or absent and touching some JDK classes can break the application. Each node packs a branch count, sorted branch characters, 16-bit values whose top bits mark leaf, bud, glob or inline-segment length, and jump offsets, with a separate table for long jumps. In cold-start JMH benchmarks it beat both the old code-based matcher (nearly 5x on Java 8) and a classic radix trie. In a Spring Boot app, name-based filtering cut instrumented startup by 20%, the trie saved another 1%, and a known-types index built on the same structure added 3%.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Java & JVM](https://swe.quest/tags/jvm.md) (Languages)
- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- JVM class loading ([easy posts on Java & JVM](https://swe.quest/tags/jvm.md?difficulty=easy))
- Java agents and instrumentation ([easy posts on Java & JVM](https://swe.quest/tags/jvm.md?difficulty=easy))
- trie data structures ([easy posts on Data structures](https://swe.quest/tags/data-structures.md?difficulty=easy))
- JVM bytecode basics ([easy posts on Java & JVM](https://swe.quest/tags/jvm.md?difficulty=easy))

## Keywords

ClassNameTrie, Datadog APM, Java Instrumentation API, premain, JMH, ldc

## Related posts

- [How we migrated our static analyzer from Java to Rust](https://swe.quest/articles/how-we-migrated-our-static-analyzer-from-java-to-rust-8d2e3080358d7827.md): Datadog Engineering · 2024-05-23 · Medium · 8 min read · Rust, Static analysis, Refactoring & migrations, Performance engineering, Java & JVM
  Datadog rewrote the Codiga static analyzer from Java to Rust after switching its parser from ANTLR to Tree-sitter, whose Java bindings lacked features like pattern matching.
- [Boosting the performance of virtual machines with Jump-Start](https://swe.quest/articles/boosting-the-performance-of-virtual-machines-with-jump-start-e63dbfae46ebd497.md): Meta Engineering · 2021-03-03 · Easy · 3 min read · Compilers, Runtimes & VMs, Performance engineering, Deployment, PHP
  Jump-Start cuts JIT warm-up overhead in HHVM by having a small slice of the fleet collect profiling data during Facebook's phased rollout.
- [Beyond API Compatibility: Building a Tool to Measure the Blast Radius of Library Changes](https://swe.quest/articles/beyond-api-compatibility-building-a-tool-to-measure-the-blast-radius-of-library-dd79bf180fb0310a.md): Netflix TechBlog · 2026-10-23 · Medium · 9 min read · API design, Static analysis, Java & JVM, Developer tools, AI agents
  Netflix's Quasar indexes symbol definitions and references across its repositories using SCIP, so library producers can see which consumers use the exact API symbols a change removes or modifies.
- [How we built a Ruby library that saves 50% in testing time](https://swe.quest/articles/how-we-built-a-ruby-library-that-saves-50-in-testing-time-128208a842ec0eb3.md): Datadog Engineering · 2024-11-01 · Hard · 12 min read · Ruby, Testing, Performance engineering, Runtimes & VMs, CI/CD
  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.
- [Fast regex search: indexing text for agent tools · Cursor](https://swe.quest/articles/fast-regex-search-indexing-text-for-agent-tools-cursor-45908cf7bb0688f8.md): Cursor · 2026-03-23 · Medium · 20 min read · Search, Data structures, Algorithms, AI agents, Developer tools
  Agents lean heavily on regex search, and ripgrep's full scan can take over 15 seconds in large monorepos, so Cursor builds local indexes specifically to accelerate regex queries.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
