Skip to content

refactor(stdune): improve path tables - #8052

Merged
rgrinberg merged 1 commit into
mainfrom
ps/rr/refactor_stdune___improve_path_tables
Jul 11, 2023
Merged

rgrinberg merged 1 commit into
mainfrom
ps/rr/refactor_stdune___improve_path_tables

Conversation

@rgrinberg

Copy link
Copy Markdown
Member

Use a more memory efficient path table. Instead of using the variant for
the key, combine 3 tables all for the individual paths.

This makes the empty table a little more bloated (3x bigger), but gives
us a saving of 2 words for every single key we store.

Signed-off-by: Rudi Grinberg [email protected]

@Alizter Alizter mentioned this pull request Jun 27, 2023
1 of 3 tasks
@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch from 3f98ef2 to fce52ee Compare July 8, 2023 13:36
@rgrinberg
rgrinberg requested a review from snowleopard July 9, 2023 10:57

@snowleopard snowleopard 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.

Looks good! I am going to benchmark this change internally too.

Comment thread otherlibs/stdune/src/path.mli Resolved
@snowleopard

snowleopard commented Jul 9, 2023 •

Copy link
Copy Markdown
Contributor

What about Path.Set and Path.Map? They are probably even bigger offenders (because we have more of them).

It's fine to leave them for another PR, just wondering if you've got plans.

Comment thread otherlibs/stdune/src/path.ml Resolved
Comment thread otherlibs/stdune/src/path.ml Resolved
@rgrinberg

Copy link
Copy Markdown
Member Author

What about Path.Set and Path.Map? They are probably even bigger offenders (because we have more of them).

I have an upcoming PR indeed.

@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch from fce52ee to 4048e01 Compare July 9, 2023 20:25
Comment thread src/dune_engine/cached_digest.ml Resolved
@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch 3 times, most recently from 93a1448 to 73ea380 Compare July 9, 2023 22:16
Comment thread src/dune_engine/cached_digest.ml Resolved
Comment thread src/dune_engine/cached_digest.ml Resolved
Comment thread otherlibs/stdune/src/path.mli Resolved
@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch 4 times, most recently from 3a26c8b to 1580f4d Compare July 10, 2023 15:25
Comment thread otherlibs/stdune/src/path.mli Resolved
@snowleopard

Copy link
Copy Markdown
Contributor

The current version of this PR still shows as a slight regression in my benchmarks.

@rgrinberg What are the results on your end?

@rgrinberg

Copy link
Copy Markdown
Member Author

Runtime performance shows a slight improvement but it's well within the noise range.

The GC stats are quite accurate and they do show a small improvement across the board, but that isn't necessarily better for performance.

Comment thread otherlibs/stdune/src/path.ml Resolved
@snowleopard

snowleopard commented Jul 10, 2023 •

Copy link
Copy Markdown
Contributor

Runtime performance shows a slight improvement but it's well within the noise range.

The GC stats are quite accurate and they do show a small improvement across the board, but that isn't necessarily better for performance.

Hmm, I wonder if we're seeing different results because we're using different sets of rules.

I'm also somewhat surprised to see a small regression in my benchmarks. It seems like this PR is mostly changing things for the better, so I'm kind of puzzled.

@rgrinberg

Copy link
Copy Markdown
Member Author

I'm not surprised that this change isn't a performance improvement, but I'm definitely surprised there's any regression. I imagined there would be no difference at all either way. I guess we should remember that OCaml hash tables aren't particularly space efficient anyway and removing a single word isn't going to change all that much.

We should note that our benchmarks are a bit biased against watch mode though. In watch mode, consuming less memory is more important because it makes subsequent operations faster. While in our measurements, we only care about the first completion build and do not care about any subsequent memory usage.

@snowleopard

Copy link
Copy Markdown
Contributor

Just a quick update: I've started some more benchmarks.

@snowleopard

Copy link
Copy Markdown
Contributor

Hah, now I'm seeing pretty consistent small improvements across most benchmarks! Maybe I botched it the first time.

Roughly: -0.1-0.2% in terms of allocations and -0.1-0.5% in terms of time.

@snowleopard snowleopard 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.

Thanks!

@snowleopard

Copy link
Copy Markdown
Contributor

@rgrinberg Btw, don't forget to switch to ~store:(module Path.Table) in Action_builder.contents. I'm making this change internally.

@snowleopard

Copy link
Copy Markdown
Contributor

@rgrinberg Btw, don't forget to switch to ~store:(module Path.Table) in Action_builder.contents. I'm making this change internally.

Just to add: with this change included, benchmarks now 2% speed-up for from-cache and null builds!

@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch from 98c16f8 to 76d37ba Compare July 11, 2023 20:46
Use a more memory efficient path table. Instead of using the variant for
the key, combine 3 tables all for the individual paths.

This makes the empty table a little more bloated (3x bigger), but gives
us a saving of 2 words for every single key we store.

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: e86dc1fe-0661-4897-9444-2dfd5f99f050 -->
@rgrinberg
rgrinberg force-pushed the ps/rr/refactor_stdune___improve_path_tables branch from 76d37ba to 07a6f95 Compare July 11, 2023 20:49
@rgrinberg
rgrinberg merged commit 9a079d0 into main Jul 11, 2023
@rgrinberg
rgrinberg deleted the ps/rr/refactor_stdune___improve_path_tables branch July 11, 2023 20:50
rgrinberg added a commit that referenced this pull request Jul 13, 2023
#8052 updated the representation for
these, but didn't bump the version.

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 72ce4eb6-2623-4c8e-9933-92a9209f25d1 -->
rgrinberg added a commit that referenced this pull request Jul 14, 2023
#8052 updated the representation for
these, but didn't bump the version.

Signed-off-by: Rudi Grinberg <[email protected]>
@Alizter Alizter added this to the 3.10.0 milestone Jul 9, 2026
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.

3 participants