-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Optimize new Gson()
#2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Optimize new Gson()
#2864
Conversation
41b38eb to
6c2e3b2
Compare
|
I'm not really convinced here. It might have been better if this had been the API from the outset, but now we have 17 years of client code that uses However, it's true that every invocation of
The last item is potentially controversial, since it does mean that some memory would end up being retained even when there are no active Whether or not we do the last item, I think the first two would be worthwhile, if only because it would eliminate the duplication whereby the default value for every Gson property is specified in both the |
|
I will drop |
e4f3797 to
f4ba10b
Compare
|
I need help about Java 9 modules... |
It looks like there is something wrong with how the adapters are looked up. It is trying to use the reflective adapter for types such as I have made some changes to this code here and proposed them as MukjepScarlet#1; that also fixes the test failures. If you are fine with them, you can merge them and they will directly appear in this PR here then. But @MukjepScarlet, could you please edit the title of this PR here (click the "Edit" button at the top right) and rename it to something like "Reduce overhead of default |
|
@eamonnmcmanus, what do you think about the current state of this PR? |
The outline looks correct, but I think there is a subtle change in behaviour. When I ran this against Google's internal tests, I saw failures that looked like this: I guess this code is running with |
|
This PR does change If you revert those |
|
I'm interesting about that too. If you think the change of |
|
I think this is the reason because stuffs like |
|
I think I am able to reproduce this locally:
Fails with the same stack trace as above. Replacing the method references in In that case maybe we could indeed replace the method references in Interestingly this only seems to affect public class SystemClassLoader extends ClassLoader {
public SystemClassLoader(ClassLoader parent) {
super(parent);
List<Supplier<?>> unused = Arrays.asList(
ArrayList::new,
LinkedHashSet::new,
TreeSet::new,
ArrayDeque::new,
// LinkedTreeMap::new,
() -> new LinkedTreeMap<>(),
LinkedHashMap::new,
TreeMap::new,
ConcurrentHashMap::new,
ConcurrentSkipListMap::new
);
}
@SuppressWarnings("SystemOut")
public static void main(String[] args) {
System.out.println("done");
}
}Edit: It seems the reason why this issue only occurs for ...
At least that is my understanding of it. But this also seems to highly depend on JDK and compiler implementation details. But given that usage of lambdas here worked before apparently, that seems to be a reasonable solution, albeit brittle. Though using Gson in general from within the constructor of a custom system class loader seems to be brittle. |
gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Marcono1234 <[email protected]>
Optimizes
new Gson()closes #2863