You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm assuming this is done to ensure the message is immutable and that makes sense.
However, most invocations of getChannel do not actually need the underlying byte[]. Some are simple null checks and in the case of RedisIndexedSessionRepository, only the String value of the message is needed.
I suggest to add a couple of default methods to Message that directly use the underlying byte[] in the DefaultMessage implementation:
Nearly all allocations can be prevented by adding these methods while still maintaining immutability and - by using default methods in the Message interface - API compatibility.
DefaultMessage.getChannel is called 3 times for every message in Spring Session. DefaultMessage.getBody once. Only one call to getChannel really needs the underlying byte array. Allocation from the other 3 calls can be avoided with my PR
Thomas Heigl opened DATAREDIS-1212 and commented
DefaultMessage.getChannel
is the method with the highest allocation rate in my application:!image-2020-09-03-09-41-19-110.png|width=765,height=142!
DefaultMessage
creates defensive clones of the underlyingbyte[]
for every invocation ofgetChannel
andgetBody:
I'm assuming this is done to ensure the message is immutable and that makes sense.
However, most invocations of
getChannel
do not actually need the underlying byte[]. Some are simple null checks and in the case ofRedisIndexedSessionRepository
, only theString
value of the message is needed.I suggest to add a couple of default methods to
Message
that directly use the underlyingbyte[]
in theDefaultMessage
implementation:Nearly all allocations can be prevented by adding these methods while still maintaining immutability and - by using default methods in the
Message
interface - API compatibility.I will create a PR for this
Attachments:
Referenced from: pull request #559
Backported to: 2.3.5 (Neumann SR5), 2.2.11 (Moore SR11)
The text was updated successfully, but these errors were encountered: