[Enhancement] Separate code and err msg in Status and save err msg in heap
Search before asking
- [X] I had searched in the issues and found no similar issues.
Description
The current Status implementation is to save all data to a fixed size (2KB) array on stack. This will lead to too large function stack space and may not be friendly to data locality (unnecessary page faults, TLB utilization, cacheline prefetching, etc.).
Another problem is when RVO(return value optimization) fails (there are many if-else branches in current codes, and the compiler may often be unable to do RVO), the move ctor cannot be used, causing the error message in Status to be copied layer by layer in the function call stack.
Doris moving the Status data from heap to stack can be traced back to https://github.com/apache/doris/pull/8117. This PR is designed to avoid dynamic memory allocation. However, in practice, we often construct error messages through fmt::format(see Status::ErrorFmt https://github.com/apache/doris/blob/a6537a90cd4fda01de4a51b7abdc23a06cc8a901/be/src/common/status.h#L284-L289), so we cannot avoid dynamic memory allocation in fact.
If we separate the status code and err msg in Status:
- The error msg constructed by
fmt::formatcan be directly moved toStatus. - When RVO fails, the compiler will use move ctor to pass
Statusto function caller to reduce the copy cost.
Solution
No response
Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct