RFC: Performance improvement in `lean_mark_persistent` and `lean_mark_mt`

Open
#16,374 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #16375 by @zgrannan — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Domain
performance

Research direction

Start with src/runtime/object.cpp around lean_mark_persistent and inspect the corresponding lean_mark_mt implementation. Review the linked implementation and benchmark results, then check the existing runtime tests and benchmark suite for coverage of persistent marking. Done means both paths preserve correct object marking and the benchmark confirms the reported instruction reduction; linked pull request #16375 is closed and unmerged.

Written by the indexing model from the issue text.

Description

lean_mark_persistent implements a worklist loop where each iteration pops an object o and:

  1. checks !lean_is_scalar(o) && lean_has_rc(o);
  2. if the check succeeds, runs lean_internal_set_rc(o, 0) and pushes all of o's children onto the worklist.

I think we can improve performance by moving the check and the update to the push:

  • only pushing a child c if !lean_is_scalar(c) && lean_has_rc(c), and
  • calling lean_internal_set_rc(c, 0) just before adding it to the worklist

This has two benefits:

  • fewer buffer operations, since scalars and already-persistent objects are never added to the buffer;
  • the worklist never holds the same object twice.

I've implemented this change here, applying the same restructuring to lean_mark_mt. Running the benchmark suite locally I get 0.96% drop in build//instructions.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More Performance issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.