This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][NFC] Replace deque with vector
ClosedPublic

Authored by HazardyKnusperkeks on Dec 3 2021, 11:53 AM.

Details

Summary

I think the deque was chosen because of a better push_front, but in combination with llvm::reverse the push_back'ed vector should be the better choice.

Diff Detail

Event Timeline

HazardyKnusperkeks requested review of this revision.Dec 3 2021, 11:53 AM
HazardyKnusperkeks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2021, 11:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Deque, contrary to the vector, doesn't need to move the elements when growing. I'm not sure if that's relevant here though.
Have you checked what's on average the maximum size of Path on some larger repo?
Maybe using llvm::SmallVector with some well-thought (data-based) static number of elements would be better here, WDYT?

MyDeveloperDay accepted this revision.Dec 4 2021, 7:12 AM

This seems reasonable its as if we only ever push_back and iterate backwards?

This revision is now accepted and ready to land.Dec 4 2021, 7:12 AM

Deque, contrary to the vector, doesn't need to move the elements when growing. I'm not sure if that's relevant here though.
Have you checked what's on average the maximum size of Path on some larger repo?
Maybe using llvm::SmallVector with some well-thought (data-based) static number of elements would be better here, WDYT?

I have not checked what the sizes are. But I have thought about reserving the upper bound (all visited states) so there is only one allocation.
The moving of the content shouldn't be problematic, since we only have pointers.

Formatting fixed.

Maybe using llvm::SmallVector with some well-thought (data-based) static number of elements would be better here, WDYT?

I tend to agree as LLVM style prefers SmallVector to vector.

Maybe using llvm::SmallVector with some well-thought (data-based) static number of elements would be better here, WDYT?

I tend to agree as LLVM style prefers SmallVector to vector.

Okay, didn't know I can use it without a number. Will update.

Even if you choose a number, beyond that number it behaves like a vector (just without the data being on the stack), its really good for small vectors but its not bad for large ones. I'm not sure what the default N is if you don't specify a number? (0?)

Even if you choose a number, beyond that number it behaves like a vector (just without the data being on the stack), its really good for small vectors but its not bad for large ones. I'm not sure what the default N is if you don't specify a number? (0?)

Yeah I know what this is. On the link ownpan provided it says it chooses a good number for the stack.

My initial take on it was since I don't know how many states we mostly have, I don't try to guess and waste space on the stack if there is a chance we always go to the heap anyway.

HazardyKnusperkeks set the repository for this revision to rG LLVM Github Monorepo.

Now with SmallVector.

owenpan accepted this revision.Jan 3 2022, 2:01 PM
This revision was landed with ongoing or failed builds.Jan 5 2022, 3:32 AM
This revision was automatically updated to reflect the committed changes.