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 creating flush ByteBuf/Segment when not necessary. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PokeMMO
Copy link

@PokeMMO PokeMMO commented Nov 2, 2019

Currently every call to update calls flush which creates a new flush buffer and segment. Even when there is no work required to be done.

ByteBufAllocator.ioBuffer is a fairly expensive call to call every update.

Unless I am doing something wrong, Kcp#check will schedule a work duration (100ms by default) not necessarily when the next "action" is required. This might be better handled by changing Kcp#check?

@szhnet
Copy link
Owner

szhnet commented Dec 31, 2019

There are check logics both checkFlushRequired and flush method. I think it is difficult to maintain. What do you think?

@PokeMMO
Copy link
Author

PokeMMO commented Dec 31, 2019

It is definitely not ideal and will cause more effort to maintain, but it is a very large performance benefit.

The other alternative is likely worse, editing flush to only create the seg and buffer when they're actually used.

https://github.com/szhnet/kcp-netty/blob/master/kcp-netty/src/main/java/io/jpower/kcp/netty/Kcp.java#L1108-L1117

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

2 participants