shashank created CAMEL-26812:
--------------------------------
Summary: camel-sanitizer - the stack taken at every first callback
makes a route about 60 times slower with the default stackDepth=32
Key: CAMEL-26812
URL: https://issues.apache.org/jira/browse/CAMEL-26812
Project: Camel
Issue Type: Improvement
Components: camel-core
Reporter: shashank
Assignee: shashank
The R1 check of {{camel-sanitizer}} (CAMEL-26714) takes the stack of the thread
at the first callback of every step call ({{StepCall.callback()}} calls
{{Sanitizer.trace()}}), so that a second callback, if one ever comes, can be
reported with both stacks. {{trace()}} walks the stack with {{StackWalker}} and
turns up to {{camel.sanitizer.stackDepth}} frames (default {{32}}) into
{{StackTraceElement}}s.
That is the main cost of the sanitizer. In the JMH run done for CAMEL-26751
(apache/camel#29528), a route of 6 steps took about 1 µs per message with the
sanitizer off and with {{stackDepth=0}}, and about 64 µs with
{{stackDepth=32}}: about 10 µs per step call. A split of 4 parts with a seda
hop went from about 4 µs to about 116 µs per message. As the default is {{32}},
a test suite run with the sanitizer on (for example {{-Psanitizer}}) pays it
for every step, and the extra time per step also changes the timing of the
races the sanitizer is meant to find.
Almost all of these stacks are thrown away: a stack is only used when the step
gets a second callback, or a callback after it threw.
Possible ways, to be measured with the same benchmark:
* keep only what a report shows: the class and method names of the frames
({{StackFrame.getClassName()}}, {{getMethodName()}}), and build the
{{StackTraceElement}}s only when a violation is reported;
* a lower default for {{stackDepth}}, such as {{8}}, which still shows the
caller of the callback in most reports;
* take the stack of the first callback only for a sample of the exchanges, or
only after a first violation was seen for that step (the report of the first
violation then has one stack less);
* document the cost next to the option.
Measured with JMH 1.37, JDK 21, 2 forks, 3 x 2 s warmup, 5 x 2 s measurement;
the numbers and the benchmark are on apache/camel#29528.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)