Skip to content

Conversation

@itkfyeah
Copy link

Avoid memory waste caused by multiple threads using many FastThreadLocal (netty#8271 netty#9328)

Motivation:

Every time one FastThreadLocal is created, the InternalThreadLocalMap.nextIndex is increased.
When multiple threads create many FastThreadLocal, the nextIndex will grow big soon.
FastThreadLocal is created much later, the InternalThreadLocalMap.indexedVariables is expanded more frequently.
But it is unnecessary.

Modifications:

Change InternalThreadLocalMap.nextIndex to instance variable.
FastThreadLocal.index is assigned by InternalThreadLocalMap of current thread.
FastThreadLocal.variablesToRemoveIndex is always zero.

Result:

InternalThreadLocalMap.indexedVariables do not need be expanded when one thread create less than 31 objects of FastThreadLocal.

…cal (netty#8271 netty#9328)

Motivation:

Every time one FastThreadLocal is created, the InternalThreadLocalMap.nextIndex is increased.
When multiple threads create many FastThreadLocal, the nextIndex will grow big soon.
FastThreadLocal is created much later, the InternalThreadLocalMap.indexedVariables is expanded more frequently.
But it is unnecessary.

Modifications:

Change InternalThreadLocalMap.nextIndex to instance variable.
FastThreadLocal.index is assigned by InternalThreadLocalMap of current thread.
FastThreadLocal.variablesToRemoveIndex is always zero.

Result:

InternalThreadLocalMap.indexedVariables do not need be expanded when one thread create less than 31 objects of FastThreadLocal.
@itkfyeah itkfyeah changed the title Avoid memory waste caused by multiple threads using many FastThreadLocal (#8271 #9328) Avoid memory waste caused by multiple threads using many FastThreadLocal(#8271 #9328) Sep 16, 2021
@itkf itkf self-assigned this Sep 16, 2021
@itkf itkf closed this Sep 16, 2021
@itkf itkf reopened this Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants