Skip to content

Use Arc instead of Box for internal expression nodes in SymbolExpr (backport #14660) #14665

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

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jun 25, 2025

Summary

This commit updates the internal construction of the SymbolExpr struct use a reference counting pointer instead of a regular pointer to a heap allocated object. The way the binary tree gets constructed internally using a normal pointer results in a lot of a copies of elements on the tree. This creates a large performance overhead for the symbol expr as we end up copying and freeing elements on the binary tree a large amount. This was the root cause of the regression reported in #14653 as the expression that gets generated by the transpiler internally ends up adding a lot of elements to global phase expression and that results in a lot of memory allocation and deallocation overhead. By using a reference counting pointer instead of creating and freeing copies of the expressions on the tree we instead only keep a single copy and just increment or decrement the reference count.

Details and comments

Fixes #14653


This is an automatic backport of pull request #14660 done by Mergify.

…14660)

This commit updates the internal construction of the SymbolExpr struct
use a reference counting pointer instead of a regular pointer to a heap
allocated object. The way the binary tree gets constructed internally
using a normal pointer results in a lot of a copies of elements on the
tree. This creates a large performance overhead for the symbol expr as
we end up copying and freeing elements on the binary tree a large
amount. This was the root cause of the regression reported in #14653
as the expression that gets generated by the transpiler internally ends
up adding a lot of elements to global phase expression and that results
in a lot of memory allocation and deallocation overhead. By using a
reference counting pointer instead of creating and freeing copies of
the expressions on the tree we instead only keep a single copy and
just increment or decrement the reference count.

Fixes #14653

(cherry picked from commit 3b26002)
@mergify mergify bot requested a review from a team as a code owner June 25, 2025 01:13
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@github-actions github-actions bot added this to the 2.1.1 milestone Jun 25, 2025
@github-actions github-actions bot added performance Changelog: Bugfix Include in the "Fixed" section of the changelog labels Jun 25, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15864966871

Details

  • 48 of 71 (67.61%) changed or added relevant lines in 3 files are covered.
  • 35 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.03%) to 87.969%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/symbol_parser.rs 3 4 75.0%
crates/circuit/src/symbol_expr.rs 44 66 66.67%
Files with Coverage Reduction New Missed Lines %
crates/transpiler/src/passes/unitary_synthesis.rs 1 94.57%
crates/circuit/src/symbol_expr.rs 4 73.85%
crates/qasm2/src/lex.rs 6 91.48%
crates/qasm2/src/parse.rs 24 96.22%
Totals Coverage Status
Change from base Build 15742171824: -0.03%
Covered Lines: 83036
Relevant Lines: 94392

💛 - Coveralls

@mtreinish mtreinish added this pull request to the merge queue Jun 25, 2025
Merged via the queue into stable/2.1 with commit 2add145 Jun 25, 2025
29 checks passed
@mtreinish mtreinish deleted the mergify/bp/stable/2.1/pr-14660 branch June 25, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants