-
Notifications
You must be signed in to change notification settings - Fork 1.2k
perf(StringRedisTemplate): avoid redundant logger creation in execute(). #3173
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
perf(StringRedisTemplate): avoid redundant logger creation in execute(). #3173
Conversation
Static logger eliminates expensive initialization per invocation. Signed-off-by: huangcanda <954060834@qq.com>
dcd43b7
to
41d4bda
Compare
Thanks for the heads up. There are a couple of other places in the codebase as well that would benefit from this kind of change. Would you like have a look and extend the PR to those, or should we take care of the rest.
Sure, I’d be happy to extend the PR.
However, since my initial change was based on a specific performance issue I encountered, I haven’t done a full review of the codebase.
If you could point me to the places you think would benefit from similar optimizations, I’ll gladly take a look and update the PR accordingly.
great - thank you!
I think we should also change the following: DefaultStreamReceiver
, JedisClusterConnection
, JedisConnection
, JedisConnectionFactory
, LettuceClusterConnection
, LettuceConnection
, LettuceConnectionFactory
, RedisAccessor
, RedisKeyValueAdapter
, RedisMessageListenerContainer
, MessageListenerAdapter
Signed-off-by: huangcanda <954060834@qq.com>
I've updated the PR based on your suggestions. Please review when convenient. Thanks!
Problem Description
Each invocation of
StringRedisTemplate.execute()
creates a newDefaultStringRedisConnection
instance, resulting in repeated initialization of non-static logger instances. This causes redundantLogFactory
lookups that consume an additional 10–15% CPU overhead.Solution
Modify the
private final Log logger
field inDefaultStringRedisConnection
toprivate static final Log logger
.Impact
10–15% reduction in CPU overhead for all Redis client command executions.