This is an archive of the discontinued LLVM Phabricator instance.

[YAML][NFC] Use BumpPtrAllocator instead of unique_ptrs
ClosedPublic

Authored by Amir on Jul 11 2023, 12:47 PM.

Details

Summary

Avoid both memory leaks and expensive dynamic allocations by using
SpecificBumpPtrAllocator for HNode types. It's expected they're not deallocated
until the Input class is destroyed, so deallocating all at once works well in
this case.

Reduces YAML profile pre-processing time in BOLT from

11.2067 (  3.2%)   1.6487 (  7.3%)  12.8554 (  3.5%)  12.8635 (  5.6%)  pre-process profile data

to

10.6613 (  3.1%)   1.6489 (  6.7%)  12.3102 (  3.3%)  12.3134 (  5.3%)  pre-process profile data

Diff Detail

Event Timeline

Amir created this revision.Jul 11 2023, 12:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 12:47 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Amir updated this revision to Diff 548365.Aug 8 2023, 2:53 PM

Use SpecificBumpPtrAllocators

Amir published this revision for review.Aug 8 2023, 3:09 PM
Amir edited the summary of this revision. (Show Details)
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 3:09 PM
Amir edited the summary of this revision. (Show Details)Aug 8 2023, 3:13 PM
Amir updated this revision to Diff 548376.Aug 8 2023, 3:15 PM

Remove Input destructor override

What are the codepaths that currently destroy these nodes? Is there any mutability in the data structure, or is it only "build build build, use, then destroy"? If it's the latter, then yeah, arena allocation seems fine.

It's possible to match unique_ptr behavior and also free memory in setCurrentDocument.

Ah, so perhaps this answers my question - the deallocation is done at TopNode = ? *nod* Wuold probably be good to match the behavior there, to avoid continuous growth.

Amir added a comment.Aug 9 2023, 12:51 PM

What are the codepaths that currently destroy these nodes?

From what I can tell there are just two: destructor of Input class and reassignment of TopNode in setCurrentDocument.

Is there any mutability in the data structure, or is it only "build build build, use, then destroy"? If it's the latter, then yeah, arena allocation seems fine.

I didn't observe any mutability, it's the latter.

It's possible to match unique_ptr behavior and also free memory in setCurrentDocument.

Ah, so perhaps this answers my question - the deallocation is done at TopNode = ? *nod* Wuold probably be good to match the behavior there, to avoid continuous growth.

Will do.

Amir updated this revision to Diff 548778.Aug 9 2023, 2:59 PM

Call DestroyAll from setCurrentDocument

dblaikie accepted this revision.Aug 9 2023, 3:08 PM

SGTM

This revision is now accepted and ready to land.Aug 9 2023, 3:08 PM
Amir added a comment.Aug 9 2023, 3:45 PM

SGTM

Thank you!

Amir edited the summary of this revision. (Show Details)Aug 9 2023, 3:46 PM
Amir updated this revision to Diff 548795.Aug 9 2023, 3:47 PM

clang-format

Amir edited the summary of this revision. (Show Details)Aug 9 2023, 4:39 PM
This revision was landed with ongoing or failed builds.Aug 9 2023, 4:42 PM
This revision was automatically updated to reflect the committed changes.