Commit 4d0bac2
Reduce allocation overhead of ExceptionLogger / LogCollector (#10684)
Reducing overhead of getting ExcetionLogger
Unlike most loggers, ExceptionLogger can be looked up repeatedly by the exception handling code woven into instrumentation.
If an instrumentation constantly creates an exception, that could cause the Logger construction to become which results in creating SLCompatHelper constantly which in turn creates String-s and byte[]-s while determined the looger level.
To avoid that problem, the LoggerHelper is cached for ExceptionLogger. We should also consider changing how the Logger is acuired, but that will be addressed in a separate PR.
Reducing allocation overhead of LogCollector
LogCollector creates RawLogMessage objects that act as keys for de-duplication. If instrumentation has a hot exception, RawLogMessage construction can become a bottleneck.
While this change doesn't eliminate RawLogMessage, it does reduce the cost of hashCode & equals which are used by the Map to de-duplicate.
hashCode is improved by using the new HashingUtils.hash which avoids the array creation needed to call the var-arg method Objects.hash.
equals is improved by special casing, this.throwable == that.throwable. While this case seems unlikely, it occurs when the JVM's hot throw optimization kicks in for NPEs.
equals is further improved by caching the result of getStackTrace. Because getStackTrace returns an array, it makes a defensive copy on each call.
By caching getStackTrace, we avoid making a copy each time equals is called.
Clean-up
Making cachedStackTrace private
For clarity, returning local stackTrace rather than cachedStackTrace
Clarifying comments
Changed hot exception to fast throw, since that in comments, since that is the name used by the JVM
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Fix broken import
Introduced a broken import while reincorporating stand-alone reproduction into code base
Sizing list appropriately
Merge branch 'dougqh/exception-logger-quick-fixes' of github.com:DataDog/dd-trace-java into dougqh/exception-logger-quick-fixes
Fixing oversight in handling of null Throwable
Adding noException case
Fixed bad copy job from stand-alone reproduction
spotless
Fixing imports
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Merge branch 'master' into dougqh/exception-logger-quick-fixes
Co-authored-by: bric3 <brice.dutheil@gmail.com>
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent 7be2605 commit 4d0bac2
File tree
5 files changed
+143
-13
lines changed- dd-java-agent
- agent-bootstrap/src
- jmh/java/datadog/trace/bootstrap
- main/java/datadog/trace/bootstrap
- agent-logging/src/main/java/datadog/trace/logging/simplelogger
- internal-api/src
- jmh/java/datadog/trace/api/telemetry
- main/java/datadog/trace/api/telemetry
5 files changed
+143
-13
lines changedLines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
58 | 82 | | |
59 | 83 | | |
60 | 84 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
Lines changed: 39 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
110 | 128 | | |
111 | 129 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
120 | 148 | | |
121 | 149 | | |
122 | 150 | | |
123 | 151 | | |
124 | | - | |
| 152 | + | |
125 | 153 | | |
126 | 154 | | |
127 | 155 | | |
0 commit comments