spring-projects / spring-projects/spring-session

Reduce allocations from Redis operations

Open
#3,207 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

RedisIndexedSessionRepository and RedisSessionExpirationPolicy create a lot of single-use proxies by relying on BoundHashOperations.

For instance in this case:

https://github.com/spring-projects/spring-session/blob/f6f4c8652e03257420bc35f44492c5dc5d4121a9/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java#L898-L903

https://github.com/spring-projects/spring-session/blob/f6f4c8652e03257420bc35f44492c5dc5d4121a9/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java#L733-L735

This showed up in our production profiler because of hundreds of MB allocated in java.lang.reflect.Method:

image

If I understand the code correctly, this is done purely for convenience and could simply be replaced by the following code:

String key = getSessionKey(sessionId);
sessionRedisOperations.opsForHash().putAll(key, this.delta);

Or am I overlooking something?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RedisIndexedSessionRepository.java at the referenced lines 733-735 and 898-903, then inspect RedisSessionExpirationPolicy for the same BoundHashOperations usage. Compare the direct Redis operations with the current behavior and verify that the change removes unnecessary allocations without altering session updates or expiration handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.