-
-
Notifications
You must be signed in to change notification settings - Fork 77
Closed

Description
While looking to obtain a bit more performance, I noticed a few things about InputStreamMessageReader
that could be addressed. See patch file in comment below. These include some minor issues, in no particular order:
- Assign values to
final
instance variables at declaration site (not in the constructor) to avoid a double assignment (the JVM will init member variables to null/0/false before constructor is called). - Limit variables to narrowest scope possible (e.g.,
rv
). - Make variables
final
. - Remove superfluous
catch
blocks. - Declare and assign variables as close to first usage as possible (e.g., endian, type, protocol version).
- Avoid use of modulus for powers of two (super minor micro optimization; javac doesn't do this one, yet, IIRC).
- Eliminate single-use variables (such as
bodylen
). - Use
finally
block to avoid duplication of variable resets.
As well as some bugs both actual and theoretical:
rv
must use an inequality relation (< 0
) because.read
can return multiple negative values. (Aside, usually compares to 0 are faster than non-zero, at least on x86 architecture.)inputChannel
, technically, could becomenull
whilereadMessage
is executing; using a local instance avoids that possibility. (This is only a problem if the reader is used from multiple threads; adding a safeguard doesn't hurt.)
Here's a screenshot of "D-Bus 4.1.1" (from main branch, no changes to the reader):
Here's a screenshot of "D-Bus 4.1.2" (patch file applied to main branch):
If I'm reading the the profiling information correctly, the changes reduce the total CPU usage by a piddly 800 ms every 200,000 ms for a very modest 0.4% overall improvement.
Attached are the .nps files that can be loaded into VisualVM 2.1.4:
Metadata
Metadata
Assignees
Labels
No labels