-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Opt out of the TypeFactory cache until we can resolve cache contention
FasterXML/jackson-databind#3876 FasterXML/jackson-benchmarks#5 The linked benchmarks show a small advantage of caching over not caching in most cases, in the best case for a cache: when a single operation is repetedly executed. In practice, the cache is used for all operations and sees heavy evictions, where contention is more likely and has greater impact on users. Given the hash collision issues that we're aware of, and the impacts we've observed, we will remove the cache until a version is available which isn't impacted by the linked issue for performance that's more predictable.
- Loading branch information
1 parent
0852a78
commit c976bd1
Showing
6 changed files
with
113 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 0 additions & 217 deletions
217
...ion/src/main/java/com/palantir/conjure/java/serialization/CaffeineCachingTypeFactory.java
This file was deleted.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
...lization/src/main/java/com/palantir/conjure/java/serialization/NonCachingTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.conjure.java.serialization; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
import com.fasterxml.jackson.databind.type.TypeModifier; | ||
import com.fasterxml.jackson.databind.type.TypeParser; | ||
import com.fasterxml.jackson.databind.util.ArrayBuilders; | ||
import com.fasterxml.jackson.databind.util.LRUMap; | ||
import com.fasterxml.jackson.databind.util.LookupCache; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* A {@link TypeFactory} implementation which does not use a cache. | ||
* @see <a href="https://github.com/FasterXML/jackson-databind/issues/3876">jackson-databind#3876</a> | ||
* @see <a href="https://github.com/FasterXML/jackson-benchmarks/pull/5">jackson-benchmarks#5</a> | ||
*/ | ||
final class NonCachingTypeFactory extends TypeFactory { | ||
|
||
NonCachingTypeFactory() { | ||
super(NoCacheLookupCache.INSTANCE); | ||
} | ||
|
||
NonCachingTypeFactory(TypeParser parser, @Nullable TypeModifier[] modifiers, ClassLoader classLoader) { | ||
super(NoCacheLookupCache.INSTANCE, parser, modifiers, classLoader); | ||
} | ||
|
||
@Override | ||
public NonCachingTypeFactory withModifier(TypeModifier mod) { | ||
return new NonCachingTypeFactory(_parser, computeModifiers(_modifiers, mod), _classLoader); | ||
} | ||
|
||
@Nullable | ||
private static TypeModifier[] computeModifiers(TypeModifier[] existing, TypeModifier newModifier) { | ||
// Semantics are based on the jackson-databind `withModifier` implementation. | ||
if (newModifier == null) { | ||
return null; | ||
} | ||
if (existing == null || existing.length == 0) { | ||
return new TypeModifier[] {newModifier}; | ||
} | ||
return ArrayBuilders.insertInListNoDup(existing, newModifier); | ||
} | ||
|
||
@Override | ||
public NonCachingTypeFactory withClassLoader(ClassLoader classLoader) { | ||
return new NonCachingTypeFactory(_parser, _modifiers, classLoader); | ||
} | ||
|
||
@Override | ||
public NonCachingTypeFactory withCache(LRUMap<Object, JavaType> _cache) { | ||
// Changes to the cache are ignored | ||
return this; | ||
} | ||
|
||
@Override | ||
public NonCachingTypeFactory withCache(LookupCache<Object, JavaType> _cache) { | ||
// Changes to the cache are ignored | ||
return this; | ||
} | ||
|
||
private enum NoCacheLookupCache implements LookupCache<Object, JavaType> { | ||
INSTANCE; | ||
|
||
@Override | ||
public int size() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public JavaType get(Object _key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public JavaType put(Object _key, JavaType _value) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public JavaType putIfAbsent(Object _key, JavaType _value) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void clear() {} | ||
|
||
@Override | ||
public String toString() { | ||
return "NoCacheLookupCache{}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.