google / emboss

Emboss is a tool for generating code that reads and writes binary data structures.
Apache License 2.0
72 stars 22 forks source link

Reduce stack use for certain arithmetic operations. #12

Closed reventlov closed 4 years ago

reventlov commented 4 years ago

It seems like there'll be a performance cliff in both cases if the variadic template ends up being hit. But I don't think there's anything to be done about it - there's no warning or info equivalent of static_assert().

For context, the largest calls to both AllKnown() and MaximumOperation::Do() tend to be generated inside of IntrinsicSizeInBytes(), where the number of arguments is approximately the number of fields in the struct. You'd have to have more than 128 fields before you get out of the O(lg(N)) domain, and you probably wouldn't notice much until at least 192 or 256 fields.

Or if your C++ compiler applies tail call optimization, it should collapse to O(N) anyway.

On a related note, I wasn't able to figure out how to write a proper regression test for this PR: I don't know of an even somewhat portable way to measure the high water mark on the stack.