-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Add 'toString' method into IdleStateEvent #9695
Add 'toString' method into IdleStateEvent #9695
Conversation
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -31,6 +32,7 @@ | |||
|
|||
private final IdleState state; | |||
private final boolean first; | |||
private String strVal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't need to cache this, since it's unlikely to be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @carl-mastrangelo ... @ursaj can you remove this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you both are mistaken in the way, how this class is used. there are only 6 shared (re-usable) instances of this class in runtime:
public class IdleStateEvent {
public static final IdleStateEvent FIRST_READER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.READER_IDLE, true);
public static final IdleStateEvent READER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.READER_IDLE, false);
public static final IdleStateEvent FIRST_WRITER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.WRITER_IDLE, true);
public static final IdleStateEvent WRITER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.WRITER_IDLE, false);
public static final IdleStateEvent FIRST_ALL_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.ALL_IDLE, true);
public static final IdleStateEvent ALL_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.ALL_IDLE, false);
So cached string value is used countless times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies to inherited instances (if any):
- either they are used in the same shared model, so this optimisation is useful;
- or they are created, used and GC-ed in a short while, so there is no harm in this optimisation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree here. If it is the case that the same idle events are reused heavily, then it stands to reason that they are shared by multiple event loops. That makes this code racy and will trigger the race detector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carl-mastrangelo generate strings on each invocation doesn't look good either. any ideas or examples how it should look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see. you've already tried to fix it in PR #9705
@@ -31,6 +32,7 @@ | |||
|
|||
private final IdleState state; | |||
private final boolean first; | |||
private String strVal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @carl-mastrangelo ... @ursaj can you remove this ?
@netty-bot test this please |
@netty-bot test this please |
@netty-bot test this please |
@ursaj thanks a lot! |
IdleStateEvent is very convenient and frequently used type of events. However both in runtime (logs) and in debug you need some manual steps to see their actual content. Default implementation generates worthless trash like this: io.netty.handler.timeout.IdleStateEvent@27f674d There are examples already, where event has convenient and useful toString implementation: * io.netty.handler.proxy.ProxyConnectionEvent * io.netty.handler.ssl.SslCompletionEvent * Implement 'IdleStateEvent.toString' method. * Unit test. More useful String representation of IdleStateEvent
Motivation: In PR netty#9695 IdleStateEvents were made to cache their string representation. The reason for this was to avoid creating garbage as these values would be used frequently. However, these objects may be used on multiple event loops and this may cause an unexpected race to occur. Modification: Only make the events that Netty creates cache their toString representation. Result: No races.
Motivation: In PR #9695 IdleStateEvents were made to cache their string representation. The reason for this was to avoid creating garbage as these values would be used frequently. However, these objects may be used on multiple event loops and this may cause an unexpected race to occur. Modification: Only make the events that Netty creates cache their toString representation. Result: No races.
Motivation: In PR #9695 IdleStateEvents were made to cache their string representation. The reason for this was to avoid creating garbage as these values would be used frequently. However, these objects may be used on multiple event loops and this may cause an unexpected race to occur. Modification: Only make the events that Netty creates cache their toString representation. Result: No races.
Motivation:
IdleStateEvent is very convenient and frequently used type of events. However both in runtime (logs) and in debug you need some manual steps to see their actual content. Default implementation generates worthless trash like this:
There are examples already, where event has convenient and useful toString implementation:
Modification: