Skip to content

Reduce integrations overhead#3380

Merged
bwoebi merged 11 commits into
masterfrom
bob/static-integrations
Sep 19, 2025
Merged

Reduce integrations overhead#3380
bwoebi merged 11 commits into
masterfrom
bob/static-integrations

Conversation

@bwoebi

@bwoebi bwoebi commented Aug 13, 2025

Copy link
Copy Markdown
Collaborator
  • Using static for integrations (avoiding carrying an Integration instance around).
  • static Closures
  • Simplify sandboxed calls, reduce them to minimum overhead
  • Only allocate new runtime cache objects when actually needed

@bwoebi
bwoebi force-pushed the bob/static-integrations branch from a4e63a4 to 66951c5 Compare August 13, 2025 13:22
@codecov-commenter

codecov-commenter commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.74%. Comparing base (e4f6598) to head (a78c4ee).
⚠️ Report is 401 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3380      +/-   ##
==========================================
- Coverage   61.87%   61.74%   -0.13%     
==========================================
  Files         141      141              
  Lines       12481    12481              
  Branches     1630     1630              
==========================================
- Hits         7722     7706      -16     
- Misses       4038     4054      +16     
  Partials      721      721              

see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4f6598...a78c4ee. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Aug 13, 2025

Copy link
Copy Markdown

Benchmarks [ tracer ]

Benchmark execution time: 2025-09-18 17:45:37

Comparing candidate commit a78c4ee in PR branch bob/static-integrations with baseline commit e4f6598 in branch master.

Found 11 performance improvements and 2 performance regressions! Performance is the same for 181 metrics, 0 unstable metrics.

scenario:ComposerTelemetryBench/benchTelemetryParsing-opcache

  • 🟩 execution_time [-1.880µs; -0.920µs] or [-13.526%; -6.618%]

scenario:ContextPropagationBench/benchExtractHeaders64Bit

  • 🟩 execution_time [-93.400ns; -30.600ns] or [-7.575%; -2.482%]

scenario:HookBench/benchHookOverheadInstallHookOnFunction

  • 🟩 execution_time [-116.111µs; -102.024µs] or [-19.750%; -17.354%]

scenario:HookBench/benchHookOverheadInstallHookOnFunction-opcache

  • 🟩 execution_time [-89.726µs; -73.826µs] or [-16.268%; -13.385%]

scenario:HookBench/benchHookOverheadInstallHookOnMethod

  • 🟩 execution_time [-98.362µs; -83.384µs] or [-16.495%; -13.984%]

scenario:HookBench/benchHookOverheadInstallHookOnMethod-opcache

  • 🟩 execution_time [-89.046µs; -67.458µs] or [-16.035%; -12.147%]

scenario:LogsInjectionBench/benchLogsInfoInjection

  • 🟩 execution_time [-680.155ns; -490.845ns] or [-9.384%; -6.772%]

scenario:LogsInjectionBench/benchLogsInfoInjection-opcache

  • 🟩 execution_time [-709.753ns; -340.647ns] or [-7.483%; -3.591%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization

  • 🟩 execution_time [-7.943µs; -7.077µs] or [-7.259%; -6.467%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache

  • 🟩 execution_time [-8.603µs; -7.517µs] or [-7.724%; -6.749%]

scenario:PHPRedisBench/benchRedisOverhead

  • 🟥 mem_peak [+209.344KB; +209.344KB] or [+4.616%; +4.616%]

scenario:PHPRedisBench/benchRedisOverhead-opcache

  • 🟥 mem_peak [+207.536KB; +207.536KB] or [+9.464%; +9.464%]

scenario:TraceSerializationBench/benchSerializeTrace

  • 🟩 execution_time [-64.122µs; -53.578µs] or [-13.582%; -11.349%]

@bwoebi
bwoebi force-pushed the bob/static-integrations branch from b5df6e7 to c81d074 Compare August 14, 2025 16:49
@pr-commenter

pr-commenter Bot commented Aug 14, 2025

Copy link
Copy Markdown

Benchmarks [ profiler ]

Benchmark execution time: 2025-09-18 16:54:28

Comparing candidate commit a78c4ee in PR branch bob/static-integrations with baseline commit e4f6598 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 28 metrics, 8 unstable metrics.

@bwoebi
bwoebi force-pushed the bob/static-integrations branch 13 times, most recently from 6005add to 350c05d Compare August 21, 2025 14:11
@bwoebi
bwoebi force-pushed the bob/static-integrations branch 7 times, most recently from 229d1fa to 908d13c Compare September 1, 2025 17:20
@bwoebi
bwoebi force-pushed the bob/static-integrations branch 2 times, most recently from ac3d79c to eb180fb Compare September 4, 2025 16:48
Signed-off-by: Bob Weinand <[email protected]>

# Conflicts:
#	src/DDTrace/Integrations/Kafka/KafkaIntegration.php
(^[\t ]++)(.*)(?<!static |_)\b(function\s*\(([^$\n]++|\n|\$(?!this))+?^\1})
by
$1$2static $3
@bwoebi
bwoebi force-pushed the bob/static-integrations branch from eb180fb to 4f9acaf Compare September 17, 2025 18:10
Signed-off-by: Bob Weinand <[email protected]>
@bwoebi
bwoebi marked this pull request as ready for review September 19, 2025 11:13
@bwoebi
bwoebi requested review from a team as code owners September 19, 2025 11:13
@bwoebi
bwoebi merged commit 4c233be into master Sep 19, 2025
1859 of 1872 checks passed
@bwoebi
bwoebi deleted the bob/static-integrations branch September 19, 2025 13:43
@github-actions github-actions Bot added this to the 1.13.0 milestone Sep 19, 2025
@marmichalski

marmichalski commented Dec 6, 2025

Copy link
Copy Markdown

Hey @bwoebi!

I did not investigate too much, but I think this PR is a cause of a change in behaviour in hooks using static methods.

We are using Instrumentation class that installs all hooks on specific classes/interfaces, something like:

<?php 

final class Instrumentation
{
    public static function commandExecutors(): void
    {
        install_hook(
            CommandExecutor::class.'::execute',
            static function (HookData $hook): void {
                $span = $hook->span();
                // ...
                $span->meta['command_executor.class'] = self::class;
                // ...
            },
        );
    }
}

Previously self would refer to the actual CommandHandler object class, just like $this in non-static closure. Now self returns Instrumentation class.

Is this expected?

@bwoebi

bwoebi commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator Author

@marmichalski Yes, that behaviour is now expected, if you want to use self:: (and have it refer to the other class), just remove static.
There was quite some overhead from rebinding Closures to class scopes, so static Closures are no longer rebound - with the option to have non-static closures bind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants