Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(stdune): improve path tables #8052

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

rgrinberg
Copy link
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
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
Copy link
Collaborator

@snowleopard snowleopard left a comment

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.

@snowleopard
Copy link
Collaborator

snowleopard commented Jul 9, 2023

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.

@rgrinberg
Copy link
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
@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
@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
@snowleopard
Copy link
Collaborator

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

@snowleopard
Copy link
Collaborator

snowleopard commented Jul 10, 2023

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
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
Collaborator

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

@snowleopard
Copy link
Collaborator

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.

Copy link
Collaborator

@snowleopard snowleopard left a comment

Choose a reason for hiding this comment

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

Thanks!

@snowleopard
Copy link
Collaborator

@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
Collaborator

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

2 participants