Skip to content
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: reuse hashmap resource in cross-service metainfo node #11

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

Ggiggle
Copy link
Contributor

@Ggiggle Ggiggle commented Nov 22, 2023

Motivation

In the design of connection resource reuse, we observed that for each new request using a reused connection, the framework side still incurs some memory allocation for data structures. Specifically, during the decoding of each request, there is behavior associated with the hashmap's **reserve_rehash**, leading us to infer that certain data structures do not retain their memory space after the request is completed.

Upon investigation, we found that at the end of each request, the cleanup of the **metainfo** node for cross-service does not use the hashmap's **clear** method. Instead, it is directly set to **None**. This causes the connection resource to regenerate a default hashmap, i.e., an empty hashmap, for the next request. Therefore, during the **insert** operation, frequent **reserve_rehash** operations occur due to the lack of reserved memory, resulting in a certain computational cost.

Solution

To achieve connection resource reuse, when cleaning up the specific data within the current connection resource for each request, we preserve the memory space for all underlying data structures. In this optimization, we primarily focus on preserving memory for the data structures used in the cross-service **metainfo** transfer. The specific approach involves implementing a **clear** method for the **Node** type, which calls the **clear** method on the encapsulated hashmap to perform data cleanup, abandoning the practice of directly setting the **Node** structure to **None**.

@Ggiggle Ggiggle self-assigned this Nov 22, 2023
@Ggiggle Ggiggle requested review from a team as code owners November 22, 2023 08:45
@Ggiggle Ggiggle merged commit 93c9a05 into main Nov 22, 2023
11 checks passed
@Ggiggle Ggiggle deleted the perf/reuse_hashmap_in_cross-service_node branch November 22, 2023 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants