11package datadog .trace .common .writer .ddagent ;
22
33import datadog .communication .serialization .EncodingCache ;
4+ import datadog .trace .common .writer .ddagent .SimpleUtf8Cache .CacheEntry ;
45import java .nio .charset .StandardCharsets ;
56import java .util .Arrays ;
67
@@ -74,6 +75,8 @@ public final class GenerationalUtf8Cache implements EncodingCache {
7475 private static final double PURGE_THRESHOLD = 0.25D ;
7576 private static final double PROMOTION_THRESHOLD_ADJ_FACTOR = 1.5 ;
7677
78+ private static final int MAX_ENTRY_LEN = 256 ;
79+
7780 private final CacheEntry [] edenEntries ;
7881 private final int [] edenMarkers ;
7982
@@ -181,12 +184,13 @@ public final byte[] getUtf8(String value) {
181184 * the specified accessTimeMs is used to update the cache entry
182185 */
183186 public final byte [] getUtf8 (String value , long accessTimeMs ) {
187+ if (value .length () > MAX_ENTRY_LEN ) return CacheEntry .utf8 (value );
188+
184189 int adjHash = CacheEntry .adjHash (value );
185190 long lookupTimeMs = this .accessTimeMs ;
186191
187192 CacheEntry [] tenuredEntries = this .tenuredEntries ;
188- int matchingTenuredIndex =
189- lookupEntryIndex (tenuredEntries , MAX_TENURED_PROBES , adjHash , value , lookupTimeMs );
193+ int matchingTenuredIndex = lookupEntryIndex (tenuredEntries , MAX_TENURED_PROBES , adjHash , value );
190194 if (matchingTenuredIndex != -1 ) {
191195 CacheEntry tenuredEntry = tenuredEntries [matchingTenuredIndex ];
192196
@@ -197,8 +201,7 @@ public final byte[] getUtf8(String value, long accessTimeMs) {
197201 }
198202
199203 CacheEntry [] edenEntries = this .edenEntries ;
200- int matchingEdenIndex =
201- lookupEntryIndex (edenEntries , MAX_EDEN_PROBES , adjHash , value , lookupTimeMs );
204+ int matchingEdenIndex = lookupEntryIndex (edenEntries , MAX_EDEN_PROBES , adjHash , value );
202205 if (matchingEdenIndex != -1 ) {
203206 CacheEntry edenEntry = edenEntries [matchingEdenIndex ];
204207
@@ -250,7 +253,7 @@ public final byte[] getUtf8(String value, long accessTimeMs) {
250253 this .earlyPromotions += 1 ;
251254
252255 edenEntries [edenMfuIndex ] = newEntry ;
253- return CacheEntry .utf8 (value );
256+ return newEntry .utf8 ();
254257 }
255258
256259 // No empty slot - or space to promote into the global cache
@@ -384,7 +387,7 @@ static final int initialBucketIndex(int[] marks, int adjHash) {
384387 }
385388
386389 static final int lookupEntryIndex (
387- CacheEntry [] entries , int numProbes , int adjHash , String value , long lookupTimeMs ) {
390+ CacheEntry [] entries , int numProbes , int adjHash , String value ) {
388391 int initialBucketIndex = initialBucketIndex (entries , adjHash );
389392 for (int probe = 0 , index = initialBucketIndex ; probe < numProbes ; ++probe , ++index ) {
390393 if (index >= entries .length ) index = 0 ;
0 commit comments