iree-org / iree-llvm-sandbox

A sandbox for quick iteration and experimentation on projects related to IREE, MLIR, and LLVM
Apache License 2.0
54 stars 31 forks source link

[Substrait] Review construction of nested protobufs in `Export.cpp` #826

Open ingomueller-net opened 5 months ago

ingomueller-net commented 5 months ago

Is there a way we could avoid make_unique's here? (well more the memory allocation parts here if this done often).

You are touching upon a question I had pending in my head: what is the best practice to assemble nested protobufs. I searched both internal and external doc and couldn't find any clear answers.

It sound plausible that using std::make_unique and set_allocated_* entails more allocations than necessary. I suppose that the better alternative is to use something like:

Inner* inner = outer->mutable_inner();
inner->set_primite(...);

If that is the case, then I'd have to restructure the whole file, so I'd like to be sure what is the best approach before starting. Can you confirm or have a good resource on the top of your head?

_Originally posted by @ingomueller-net in https://github.com/iree-org/iree-llvm-sandbox/pull/817#discussion_r1601225353_