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

Avoid triggering type cache pollution on VertxContext.isDuplicatedContext #190

Merged
merged 1 commit into from Oct 17, 2022

Conversation

Sanne
Copy link
Contributor

@Sanne Sanne commented Oct 17, 2022

This is a strong performance enhancement.
Using @franz1981's new agent we can now identify suboptimal code in our libraries when doing instanceof (or comparable, such as casts) operations which trigger JDK-8180450.

It would seem we have one of such cases in method VertxContext.isDuplicatedContext , the related portion of the report being:

--------------------------
2:	io.vertx.core.impl.DuplicatedContext
Count:	24323910
Types:
	io.vertx.core.impl.ContextInternal
	io.vertx.core.Context
Traces:
	io.smallrye.common.vertx.VertxContext.isDuplicatedContext(VertxContext.java:114)
		class: io.vertx.core.Context
		count: 11809285
	io.smallrye.common.vertx.VertxContext.isDuplicatedContext(VertxContext.java:115)
		class: io.vertx.core.impl.ContextInternal
		count: 10516203
	io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:135)
		class: io.vertx.core.impl.ContextInternal
		count: 509081
	io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:561)
		class: io.vertx.core.impl.ContextInternal
		count: 505264
	io.vertx.ext.web.impl.RoutingContextImpl.getEndHandlers(RoutingContextImpl.java:508)
		class: io.vertx.core.impl.ContextInternal
		count: 494211
	io.vertx.core.streams.impl.InboundBuffer.<init>(InboundBuffer.java:95)
		class: io.vertx.core.impl.ContextInternal
		count: 489866
--------------------------

As one can see, the common pattern is to cast an instance of io.vertx.core.impl.ContextInternal to io.vertx.core.impl.ContextInternal; there's only one exception here perturbing the cache: this method is implicitly casting to its obvious interface io.vertx.core.Context.

The fix is simple: consistently cast to io.vertx.core.impl.ContextInternal exclusively.

Copy link
Contributor

@franz1981 franz1981 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @Sanne ! LGTM

@radcortez
Copy link
Member

@Sanne, you should be signing your commits :)

@radcortez radcortez merged commit cc6f385 into smallrye:main Oct 17, 2022
@Sanne Sanne deleted the AvoidTypeCachePollutions branch October 17, 2022 17:25
@radcortez radcortez added this to the 1.13.2 milestone Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants