---
title: "Performance improvements in the Datadog Agent metrics pipeline"
description: "Profiling the Go-based Datadog Agent under heavy DogStatsD load showed that computing a unique context key per metric, especially sorting and deduplicating tags, dominated CPU."
url: "https://swe.quest/articles/performance-improvements-in-the-datadog-agent-metrics-pipeline-2d01cccf9e289314"
canonical: "https://www.datadoghq.com/blog/engineering/performance-improvements-in-the-datadog-agent-metrics-pipeline/"
source: "Datadog Engineering"
published: "2023-01-31"
difficulty: "medium"
kind: "Case study"
reading_minutes: 11
tags: ["performance","go","observability","algorithms"]
---

# Performance improvements in the Datadog Agent metrics pipeline

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2023-01-31, 11 min read, Case study. Original: [https://www.datadoghq.com/blog/engineering/performance-improvements-in-the-datadog-agent-metrics-pipeline/](https://www.datadoghq.com/blog/engineering/performance-improvements-in-the-datadog-agent-metrics-pipeline/)

## Summary

Profiling the Go-based Datadog Agent under heavy DogStatsD load showed that computing a unique context key per metric, especially sorting and deduplicating tags, dominated CPU. Datadog specialized the sort by tag count, switched to murmur3 with 64-bit keys to hit Go's fast map paths, and then replaced ordered hash chaining with order-independent XOR of tag hashes, deduplicated through a reusable fixed-size custom hash set that removes sorting entirely. Micro-benchmarks show context generation 11–80% faster depending on tag count, and at ~200k metrics/s on 4-core VMs Agent CPU fell about 40% (1 core vs 1.6).

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Go](https://swe.quest/tags/go.md) (Languages)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- Go profiling and benchmarks ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))
- hash tables
- flamegraphs

## Keywords

Datadog Agent, DogStatsD, murmur3, pprof, benchstat, XOR hashing

## Related posts

- [Scaling down to speed up: How we improved efficiency of live process metrics by 100x](https://swe.quest/articles/scaling-down-to-speed-up-how-we-improved-efficiency-of-live-process-metrics-by-db520ecc99ab0c49.md): Datadog Engineering · 2025-08-12 · Medium · 8 min read · Observability, Scaling, Cost optimization, Queues & messaging, System design
  Datadog cut real-time process and container metric traffic by about 100x by enabling 2-second live collection only on hosts whose processes a user is actually viewing (at most 50 per user), instead of on every host in the tenant.
- [How we scaled metrics aggregation by moving durable state into storage](https://swe.quest/articles/how-we-scaled-metrics-aggregation-by-moving-durable-state-into-storage-09bea3fd544962da.md): Datadog Engineering · 2026-11-17 · Medium · 12 min read · Stream processing, Scaling, Observability, Storage engines, Distributed systems
  Datadog's metrics aggregation service, which merges DDSketch distributions to reduce tag dimensions, went through three generations as volume grew roughly 10× each time.
- [From hand-tuned Go to self-optimizing code: Building BitsEvolve](https://swe.quest/articles/from-hand-tuned-go-to-self-optimizing-code-building-bitsevolve-65732e9f0f979e91.md): Datadog Engineering · 2025-09-18 · Medium · 17 min read · Performance engineering, Go, AI agents, Cost optimization, Compilers
  Datadog cut CPU in Go hot paths by removing compiler bounds checks in NormalizeTag (25% faster, 0.75% service CPU) and adding an ASCII fast path to NormalizeTagArbTagValue (90% faster, hundreds of thousands of dollars in projected annual savings), guided by production data showing nearly all inputs were ASCII.
- [How Uken Games reduces observability costs by 87% with ClickHouse](https://swe.quest/articles/how-uken-games-reduces-observability-costs-by-87-with-clickhouse-b3d46180eaebbbed.md): ClickHouse · 2026-09-01 · Medium · 7 min read · Observability, Cost optimization, Analytics & OLAP, Games
  Uken Games replaced Datadog with an open-source observability stack: OpenTelemetry collectors in an agent-plus-gateway layout, SigNoz on a single ClickHouse node for traces, AWS-managed Prometheus for metrics, CloudWatch for logs, and Grafana alerts defined as code via a custom CloudFormation resource.
- [How we reduced the size of our Agent Go binaries by up to 77%](https://swe.quest/articles/how-we-reduced-the-size-of-our-agent-go-binaries-by-up-to-77-01b71ba25e3ec4b1.md): Datadog Engineering · 2026-02-18 · Medium · 14 min read · Go, Build systems, Compilers, Performance engineering
  Datadog cut its Agent's Go binary sizes by up to 77% between versions 7.60.0 and 7.68.0 without removing features.

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)
