Skip to content

Optimize class ExceptionStateSet to improve both runtime and memory usage. #171

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ZhangChangICB
Copy link

@ZhangChangICB ZhangChangICB commented Jan 13, 2025


motivation && reason

Under the original ExceptionStateSet architecture, we observed that during the process of exception propagation, the STA would attempt to create an ExceptionStateSet for each specific Vertex and Tag, even if it was entirely unrelated to that point and could have been completely copied from the ExceptionStateSet of the previous stage. Like following:

if (states == nullptr)
  states = new ExceptionStateSet();
states->insert(state);

This meant that a large number of identical ExceptionStateSet instances were created, even though their contents were exactly the same, leading to unnecessary memory overhead.

Furthermore, under this architecture, every time a Tag Match was performed, the STA needed to repeatedly compare the elements within the ExceptionStateSet. Additionally, when calculating the Tag Hash, it had to repeatedly iterate over and compute the hash values of each Exception in the ExceptionStateSet. This resulted in significant additional runtime overhead.


action && improvement

We refactored the ExceptionStateSet structure and observed over a 5% runtime improvement through testing with the pprof tool on our test design, along with minor memory optimizations. The changes we made include the following:

  1. Ensured that ExceptionStateSet instances with identical contents are treated as the same element.
  2. With the above adjustment, Tag Match/Exception Match operations can now match pointers instead of comparing their actual contents.
  3. Cached the hash of the ExceptionStateSet, eliminating the need to recalculate it every time a Tag is created.
  4. Replaced the use of OwnState for memory management with a reference counting (refCount) approach.

pprof data && evidence

Under design with about 150k instances, 4 corners, dozens of exceptions && clocks.
Read design and find requireds.

  • Before this pull request:
    before_this_pr.pdf

  • After this pull request:
    after_this_pr.pdf
    You can see the sample time percentage of function "findTag" improved from 12.3% to 5.9%.


@CLAassistant
Copy link

CLAassistant commented Jan 13, 2025

CLA assistant check
All committers have signed the CLA.

@ZhangChangICB ZhangChangICB changed the title Optimize structure ExceptionStateSet to improve both runtime and memory usage. Optimize class ExceptionStateSet to improve both runtime and memory usage. Jan 13, 2025
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