Skip to content

Fix Gc.quick_stat documentation#13424

Merged
kayceesrk merged 1 commit into
ocaml:trunkfrom
jmid:quick-stat-docs
Sep 14, 2024
Merged

Fix Gc.quick_stat documentation#13424
kayceesrk merged 1 commit into
ocaml:trunkfrom
jmid:quick-stat-docs

Conversation

@jmid
Copy link
Copy Markdown
Member

@jmid jmid commented Sep 8, 2024

While torturing the poor Gc module, a test spotted that the Gc.quick_stat documentation was a bit off.

  • the promised live_words, live_blocks, free_words, and fragments fields are not zero
  • the largest_free and stack_size fields returned by Gc.stat are also 0 (along with heap_chunks and free_blocks - as documented in the stat record type at the top) and hence better be documented in the stat function
  • nit alert: while not being a native speaker, I believe singular "this metric" is preferable

I can see #12850 included in 5.2.0 made adjustments to the Gc.quick_stat functionality and documentation, but OCaml5 has returned non-zero fields for these entries since 5.0.0 AFAICS.

A top-level example to illustrate:

OCaml version 5.4.0+dev0-2024-08-25
Enter #help;; for help.

Gc.compact ();;
- : unit = ()
Gc.quick_stat ();;
- : Gc.stat =
{Gc.minor_words = 757748.; promoted_words = 204684.; major_words = 402624.;
 minor_collections = 18; major_collections = 9; heap_words = 435112;
 heap_chunks = 0; live_words = 349577; live_blocks = 80388;
 free_words = 82724; free_blocks = 0; largest_free = 0; fragments = 2811;
 compactions = 1; top_heap_words = 485635; stack_size = 0;
 forced_major_collections = 2}
Gc.stat ();;
- : Gc.stat =
{Gc.minor_words = 794089.; promoted_words = 205774.; major_words = 403714.;
 minor_collections = 24; major_collections = 12; heap_words = 435112;
 heap_chunks = 0; live_words = 349957; live_blocks = 80491;
 free_words = 82344; free_blocks = 0; largest_free = 0; fragments = 2811;
 compactions = 1; top_heap_words = 485635; stack_size = 0;
 forced_major_collections = 3}

Copy link
Copy Markdown
Member

@damiendoligez damiendoligez left a comment

Choose a reason for hiding this comment

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

LGTM

@damiendoligez
Copy link
Copy Markdown
Member

@jmid: do you want to add an entry to the Changes file? I don't think it's necessary here, but if you want to get credit for these changes, that's the place.

@jmid
Copy link
Copy Markdown
Member Author

jmid commented Sep 10, 2024

Thanks! I've added a Changes entry, thinking that users of these may potentially like to know.
I added the entry to the 5.3 section, as I'm expecting this documentation fix to be cherry-picked to 5.3.

@Octachron
Copy link
Copy Markdown
Member

Octachron commented Sep 10, 2024

Indeed, documentation fixes should be cherry-picked to 5.3 (at least until the first rc).

Comment thread stdlib/gc.mli Outdated
This function is much faster than [stat] because it does not need to
(** Returns a record with the current values of the memory management counters
like [stat]. Due to per-domain buffers it may only represent the state of
the program's total memory usage since the last minor collection or major
Copy link
Copy Markdown
Contributor

@kayceesrk kayceesrk Sep 10, 2024

Choose a reason for hiding this comment

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

Are we sure this should be “since”? It does not read right to me. The number of minor GCs since the last minor GC will be 0, but what quick_stat returns is different. How about:

(** Returns a record with the current values of the memory management 
    counters like [stat]. Unlike [stat], [quick_stat] does not perform a full major 
    collection, and hence, is much faster. However, [quick_stat] reports the 
    counters sampled at the last minor collection or at the end of the last major 
    collection cycle (whichever is the latest). Hence, the memory stats returned 
    by [quick_stat] are not instantaneously accurate. *)

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.

Also, in the original comment, I am not sure which field the program's total memory usage is supposed to represent (if at all). The documentation attached to stats refers to the program's total memory stats, while being vague, is a bit more accurate. I did wonder whether usage was supposed to be stats.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good to me!
The reordering of sentences also improve readability IMO, mentioning the central difference first and only secondly going into more detail.

@kayceesrk
Copy link
Copy Markdown
Contributor

@jmid Would you be able to squash the commits into a single commit?

@jmid
Copy link
Copy Markdown
Member Author

jmid commented Sep 12, 2024

Sure, squashed and force pushed 👍

@kayceesrk kayceesrk merged commit 00d89ea into ocaml:trunk Sep 14, 2024
@kayceesrk
Copy link
Copy Markdown
Contributor

Thanks

@jmid jmid deleted the quick-stat-docs branch September 15, 2024 15:57
@jmid
Copy link
Copy Markdown
Member Author

jmid commented Sep 18, 2024

Indeed, documentation fixes should be cherry-picked to 5.3 (at least until the first rc).

Gentle reminder to cherry-pick this documentation fix to 5.3

@kayceesrk
Copy link
Copy Markdown
Contributor

Gentle reminder to cherry-pick this documentation fix to 5.3

FYI @Octachron. Is there a label that we use to indicate that certain PRs are marked for cherry-picking to the release branch?

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 18, 2024

Please feel free to cherry-pick yourself after merging, there is documentation on the specific git incantation recommended at https://github.com/ocaml/ocaml/blob/trunk/HACKING.adoc#keep-merge-commits-when-merging-and-cherry-picking-github-prs

@Octachron
Copy link
Copy Markdown
Member

A label could be helpful when checking that no bug fixes was forgotten. Maybe a whole set 5.3-bugfix, 5.3-docfix and 5.3-configfix?

@kayceesrk kayceesrk added this to the 5.3 milestone Sep 23, 2024
@kayceesrk
Copy link
Copy Markdown
Contributor

A label could be helpful when checking that no bug fixes was forgotten. Maybe a whole set 5.3-bugfix, 5.3-docfix and 5.3-configfix?

Alternatively, adding this to the 5.3 milestone may be better to avoid polluting the labels namespace with many different labels per release? I've done so now.

@jmid
Copy link
Copy Markdown
Member Author

jmid commented Sep 23, 2024

The milestone has the downside of marking things as 'Closed' once a PR is merged, thus risking to forget to cherry-pick 🤷

dra27 pushed a commit that referenced this pull request Oct 2, 2024
Fix Gc.quick_stat documentation

(cherry picked from commit 00d89ea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants