[llvm] [BOLT] Release pseudo-probe decoder after emit (PR #211935)
Rafael Auler via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 14:54:27 PDT 2026
https://github.com/rafaelauler created https://github.com/llvm/llvm-project/pull/211935
PseudoProbeRewriter builds sizable data structures and then hold onto them after they are needed.
PseudoProbeRewriter::postEmitFinalizer() parses the input .pseudo_probe sections into an MCPseudoProbeDecoder whose address-to-probe and GUID-to-function-desc maps can be very large (tens of GiB on big binaries with many probes). This is not used again once probes have been updated, yet they survive into the memory-heavy DWARF rewrite (updateDebugInfo), directly inflating BOLT's peak RSS at the worst possible time.
This frees them at the end of the postEmitFinalizer() calls, before updateDebugInfo runs.
Stacked on top of the .dwo DIE diff, in large binaries you should observe ~17% peak RSS wins if your
build uses pseudo probe maps.
>From 7273146c8b3b0ea4017fe15e4145ee5e4ab7ddd3 Mon Sep 17 00:00:00 2001
From: Rafael Auler <rafaelauler at fb.com>
Date: Fri, 10 Jul 2026 17:45:21 -0700
Subject: [PATCH] [BOLT] Release pseudo-probe decoder after emit
Summary:
PseudoProbeRewriter builds sizable data structures and then
hold onto them after they are needed.
PseudoProbeRewriter::postEmitFinalizer() parses the input
.pseudo_probe sections into an MCPseudoProbeDecoder whose
address-to-probe and GUID-to-function-desc maps can be very large
(tens of GiB on big binaries with many probes). This is not used again
once probes have been updated, yet they survive into the memory-heavy
DWARF rewrite (updateDebugInfo), directly inflating BOLT's peak RSS at
the worst possible time.
This frees them at the end of the postEmitFinalizer() calls, before
updateDebugInfo runs.
---
bolt/include/bolt/Core/BinaryContext.h | 5 +++++
bolt/lib/Rewrite/PseudoProbeRewriter.cpp | 7 +++++++
bolt/lib/Rewrite/SDTRewriter.cpp | 2 ++
3 files changed, 14 insertions(+)
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index 670832288ecbd..8a4892d72e7b8 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -427,6 +427,11 @@ class BinaryContext {
PseudoProbeDecoder = Decoder;
}
+ /// Release the pseudo probe decoder once probes have been updated, freeing its
+ /// (potentially large) address-to-probe maps before later, memory-heavy
+ /// phases such as debug info rewriting.
+ void resetPseudoProbeDecoder() { PseudoProbeDecoder.reset(); }
+
/// Return BinaryFunction containing a given \p Address or nullptr if
/// no registered function contains the \p Address.
///
diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
index 947d8992890d4..89f23d5ea72df 100644
--- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
+++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
@@ -104,6 +104,13 @@ Error PseudoProbeRewriter::postEmitFinalizer() {
parsePseudoProbe();
updatePseudoProbes();
+ // The decoder's address-to-probe maps can be very large and are no longer
+ // needed once probes have been updated. Release both our reference and the
+ // one held by BinaryContext so the memory is freed before the memory-heavy
+ // debug info rewriting phase runs.
+ BC.resetPseudoProbeDecoder();
+ ProbeDecoderPtr.reset();
+
return Error::success();
}
diff --git a/bolt/lib/Rewrite/SDTRewriter.cpp b/bolt/lib/Rewrite/SDTRewriter.cpp
index b4854665fbc81..f32ace0bd6986 100644
--- a/bolt/lib/Rewrite/SDTRewriter.cpp
+++ b/bolt/lib/Rewrite/SDTRewriter.cpp
@@ -156,6 +156,8 @@ Error SDTRewriter::postEmitFinalizer() {
SDTNotePatcher->addLE64Patch(SDTInfo.PCOffset, NewAddress);
}
+ SDTMarkers.clear();
+
return Error::success();
}
More information about the llvm-commits
mailing list