Skip to content
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

Introduce interface cache for proxied EntityManager and Query types #23345

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Jul 23, 2019

We now reuse interfaces for EntityManager and Query classes that are proxied through ExtendedEntityManagerCreator and SharedEntityManagerCreator.

These caches prevent excessive object allocations through ClassUtils.getAllInterfacesForClass(…) and ClassUtils.getAllInterfacesForClassAsSet(…).

Example benchmark:

@State(Scope.Benchmark)
@Fork(value = 1)
public class EmBenchmark {

	EntityManager em;

	@Setup
	public void prepare() {

		EntityManagerFactory emf = …;
		em = SharedEntityManagerCreator.createSharedEntityManager(emf, null);
	}

	@Benchmark
	public void measure(Blackhole voodoo) {
		voodoo.consume(em.createQuery("SELECT p FROM Person p"));
	}
}

Measurement:

Before:
Benchmark                Mode  Cnt       Score        Error  Units
EmBenchmark.measureJpa  thrpt    5  650483,423  ± 29876,924  ops/s

After:
Benchmark                Mode  Cnt       Score        Error  Units
EmBenchmark.measureJpa  thrpt    5  734358,219  ± 74288,478  ops/s

We now reuse interfaces for EntityManager and Query classes that
are proxied through ExtendedEntityManagerCreator and SharedEntityManagerCreator.

These caches prevent excessive object allocations through
ClassUtils.getAllInterfacesForClass(…) and
ClassUtils.getAllInterfacesForClassAsSet(…).
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 23, 2019
@jhoeller jhoeller self-assigned this Aug 1, 2019
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 1, 2019
@jhoeller jhoeller modified the milestones: 5.2 RC2, 5.2 RC1 Aug 1, 2019
@jhoeller jhoeller merged commit 1890e04 into spring-projects:master Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants