Lots of unnecessary copies of `object_ref`
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- [X ] Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
Move constructors for objects deriving from object_ref in lean are making a copy, probably due to the assumption that an rvalue reference is propagated as such across function calls.
Example:
expr(expr && other):object_ref(other)
should be:
expr(expr && other):object_ref(std::move(other))
As a result, there are a lot of unnecessary incref/decref calls on object_ref. We've measured that expr copying and assignment by itself uses 10% of total runtime on our workloads.
Context
No specific context.
Steps to Reproduce
Expected behavior:
expr::expr(expr&& other) calls object_ref::object_ref(object_ref&&), which steals refcount from other, no incref happens.
Actual behavior:
expr::expr(expr&& other) calls object_ref::object_ref(const object_ref&), which increfs other's refcount. Then the callee decrefs other's refcount.
Versions
v4.7.0
Additional Information
n/a
Impact
Performance only.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the C++ move constructors for objects deriving from object_ref, using the reported expr::expr(expr&& other) example as the entry point. Compare their object_ref initialization with the expected and actual behavior described in the issue, then verify that relevant move paths avoid unnecessary incref/decref operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100