Skip to content

Avoid re-marking ephemerons with trivial data - #13827

Merged
stedolan merged 1 commit into
ocaml:trunkfrom
stedolan:unremarkable-ephemerons
Feb 25, 2025
Merged

Avoid re-marking ephemerons with trivial data#13827
stedolan merged 1 commit into
ocaml:trunkfrom
stedolan:unremarkable-ephemerons

Conversation

@stedolan

Copy link
Copy Markdown
Contributor

In general, ephemerons may need to be marked more than once, if new marking has occurred since ephemeron marking began. This patch optimises this logic: re-marking is never necessary if the data field of the ephemeron is trivial. This optimisation was present in OCaml 4, and is important for Stdlib.Weak, which only uses ephemerons with trivial data.

This means that programs using Weak will only do one pass over the ephemeron set, since the ephemerons backing weak tables will be removed from the todo list once they are scanned.

cc @nojb who's interested in testing this: could you report the OCAMLRUNPARAM=v=0xfff GC logs on your test case before and after this patch, as well as timings?

@nojb

nojb commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

cc @nojb who's interested in testing this: could you report the OCAMLRUNPARAM=v=0xfff GC logs on your test case before and after this patch, as well as timings?

Will do.

@nojb

nojb commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

cc @nojb who's interested in testing this: could you report the OCAMLRUNPARAM=v=0xfff GC logs on your test case before and after this patch, as well as timings?

Will do.

Full GC logs corresponding to 5.3.0 and this PR, with timings (in s):

GC-full-530.txt -> 11.7287089825
GC-full-13827.txt -> 7.53212308884

By comparison, the 4.14 time is 6.33123278618.

@jberdine jberdine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW code change LGTM

@NickBarnes NickBarnes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is correct; naming quibbles.

Comment thread runtime/major_gc.c Outdated
Comment thread runtime/major_gc.c Outdated
In general, ephemerons may need to be marked more than once, if new marking
has occurred since ephemeron marking began. This patch optimises this logic:
re-marking is never necessary if the data field of the ephemeron is trivial.
This optimisation was present in OCaml 4, and is important for Stdlib.Weak,
which only uses ephemerons with trivial data.
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.

4 participants