Skip to content

Cache the Java serializer lookup per type - #1300

Merged
theigl merged 2 commits into
EsotericSoftware:masterfrom
vpaturet:externalizable-serializer-lookup-cache-fix
Aug 20, 2026
Merged

Cache the Java serializer lookup per type#1300
theigl merged 2 commits into
EsotericSoftware:masterfrom
vpaturet:externalizable-serializer-lookup-cache-fix

Conversation

@vpaturet

@vpaturet vpaturet commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This fixes issue #1299 by implementing the missing logic in the ExternalizableSerializer cache.

@theigl

theigl commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

I'm wondering if we should replace this whole lookup with a ClassValue.

	private final ClassValue<JavaSerializer> javaSerializerByType = new ClassValue<>() {
		protected JavaSerializer computeValue(Class<?> type) {
			return isJavaSerializerRequired(type) ? new JavaSerializer() : null;
		}
	};

Then the whole method just becomes:

	private JavaSerializer getJavaSerializerIfRequired (Class type) {
		return javaSerializerByType.get(type);
	}

This is faster than the map lookup and much cleaner.

@vpaturet

Copy link
Copy Markdown
Contributor Author

This looks much better! I added one more commit with your suggestion.

@theigl
theigl merged commit 30a6563 into EsotericSoftware:master Aug 20, 2026
1 check passed
@theigl

theigl commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Thank you @vpaturet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants