Skip to content

Refactor jank to use events #1175

Merged
LikeTheSalad merged 18 commits intoopen-telemetry:mainfrom
breedx-splk:refactor_jank_for_events
Aug 28, 2025
Merged

Refactor jank to use events #1175
LikeTheSalad merged 18 commits intoopen-telemetry:mainfrom
breedx-splk:refactor_jank_for_events

Conversation

@breedx-splk
Copy link
Copy Markdown
Contributor

Resolves #904.

Also attempts to address the prototype implementation in open-telemetry/semantic-conventions#2552.

This was done in a way that allows us to continue emitting the zero-duration span, but to mark it as deprecated for a release and remove it in the next release.

@breedx-splk breedx-splk requested a review from a team as a code owner August 20, 2025 22:05
Copy link
Copy Markdown
Contributor

@cleverchuk cleverchuk left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

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

LGTM. Nothing blocking. The leak in the case of a removal of the SlowRenderListener before clean up should be straightforward, but it's theoretical and if you don't think it'll happen, don't worry about it.

private val frameMetricsHandler: Handler,
private val pollInterval: Duration,
) : DefaultingActivityLifecycleCallbacks {
private val activities: ConcurrentMap<Activity, PerActivityListener> = ConcurrentHashMap()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In case this callback is removed before it has a chance to process the deregistration of the listener for a particular activity, I'd use a WeakHashMap and WeakReference keys here as we don't want this to be the only reference preventing the GC of a dead Activity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree we should avoid keeping hard references to Activities.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, you really got me thinking about this. 😅 It would be quite undesirable indeed to leak Activity references. I've looked at it from a few different angles and have just concluded that it's complicated.

I'm not sure how it could happen, other than via SlowRenderingInstrumentation.uninstall() which both unregisters the listener, shuts down the SlowRenderListener which removes all the frame listeners and clears the activity map, and then it nulls its own reference...which should allow it to be GCd anyway. Agreed?

So if I reason through that I think we're already covered...unless you have another way that this listener might get deregistered?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because it's been this way for a LONG time, and In the interest of moving forward, I'll open an issue for this and we can tackle it in a follow-up effort.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok #1192
I think we might also have a problem with referencing the wrong Window instance if/when an Activity changes it. Please have a look.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it. I didn't realize we've been doing it this way all this time. I think we can move forward with this for the purposes of migrating to the new spec, though we should definitely try to address that new issue asap.

@LikeTheSalad LikeTheSalad merged commit 95679ae into open-telemetry:main Aug 28, 2025
6 checks passed
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.

Migrate slow rendering instrumentation from spans to events

4 participants