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

Avoid quadratic memory blowup in TermDag::to_string #496

Merged

Conversation

RiscInside
Copy link
Contributor

@RiscInside RiscInside commented Dec 13, 2024

Zulip

Current version of TermDag::to_string caches a string for each DAG node. This results in quadratic memory blowup (these strings contain each other) which prevents vector benchmark from running on my machine.

This PR fixes the issue by building one result string and using string ranges to refer to already built substrings. Memory consumption should now be proportional to the length of the string. This also avoids quite a few allocations.

With these changes I am finally able to run the benchmark (it used to OOM for me). In conjunction with the other PR, full running time is now under a second.

@RiscInside RiscInside requested a review from a team as a code owner December 13, 2024 18:59
@RiscInside RiscInside requested review from Alex-Fischman and removed request for a team December 13, 2024 18:59
Copy link

codspeed-hq bot commented Dec 13, 2024

CodSpeed Performance Report

Merging #496 will not alter performance

Comparing RiscInside:iurii/faster-termdag-to-string (bae753c) with main (0d03377)

Summary

✅ 8 untouched benchmarks

@RiscInside
Copy link
Contributor Author

RiscInside commented Dec 13, 2024

For reference, the generated string is 889MB! We don't want to compute it if user didn't ask for it.

@RiscInside RiscInside force-pushed the iurii/faster-termdag-to-string branch from 5a1863d to bae753c Compare December 13, 2024 20:32
Copy link
Collaborator

@yihozhang yihozhang left a comment

Choose a reason for hiding this comment

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

Thanks!

@yihozhang yihozhang merged commit 3df83aa into egraphs-good:main Dec 13, 2024
5 checks passed
@RiscInside RiscInside deleted the iurii/faster-termdag-to-string branch December 15, 2024 11:33
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