Skip to content

Avoid wrapping scheduled Runnables in Callable adapter#9666

Merged
normanmaurer merged 2 commits intonetty:4.1from
njhill:dont-wrap-runnables
Oct 17, 2019
Merged

Avoid wrapping scheduled Runnables in Callable adapter#9666
normanmaurer merged 2 commits intonetty:4.1from
njhill:dont-wrap-runnables

Conversation

@njhill
Copy link
Copy Markdown
Member

@njhill njhill commented Oct 15, 2019

Motivation

Currently when future tasks are scheduled via schedule(Runnable, ...) methods, the supplied Runnable is wrapped in a newly allocated Callable adapter prior to being wrapped in a ScheduledFutureTask.

This can be avoided which saves an object allocation per scheduled task.

Modifications

Change the Callable task field of ScheduledFutureTask to be of type Object so that it can hold/run Runnables directly in addition to Callables.

An "adapter" is still used in the case a Runnable is scheduled with an explicit constant non-null completion value, assumed to be rare.

Result

Less garbage

Motivation

Currently when future tasks are scheduled via schedule(Runnable, ...)
methods, the supplied Runnable is wrapped in a newly allocated Callable
adapter prior to being wrapped in a ScheduledFutureTask.

This can be avoided which saves an object allocation per scheduled task.

Modifications

Change the Callable task field of ScheduledFutureTask to be of type
Object so that it can hold/run Runnables directly in addition to
Callables.

An "adapter" is still used in the case a Runnable is scheduled with an
explicit constant non-null completion value, assumed to be rare.

Result

Less garbage
@netty-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

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

Good one!

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer added this to the 4.1.43.Final milestone Oct 17, 2019
@normanmaurer normanmaurer merged commit 19b4adf into netty:4.1 Oct 17, 2019
@normanmaurer
Copy link
Copy Markdown
Member

@njhill thanks a lot! I also did mark it for "needs back port". Please check if this applicable and if so do it once you have cycles :)

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.

3 participants