pitrou opened a new issue, #51834: URL: https://github.com/apache/arrow/issues/51834
### Describe the bug, including details regarding any error messages, version, and platform. While investigating some of the CI failures in https://github.com/apache/arrow/pull/51758, it came to me that each use of `ARROW_ASSIGN_OR_RAISE` added stack consumption through an additional uniquely-named local variable to hold the temporary `Result<T>`. A lexical sequence of `ARROW_ASSIGN_OR_RAISE` will therefore consume N times the necessary stack space, as this sample code shows: ```c++ using BigObject = std::array<uint8_t, 128>; ARROW_NOINLINE Result<BigObject> ReturnSomethingBig() { return BigObject{}; } ARROW_NOINLINE Status PrintStack(int depth = 0, uint8_t* last_stack = nullptr) { uint8_t x; if (last_stack) { ARROW_LOG(INFO) << "Depth " << depth << " -> stack: " << (void*)(&x) << " -> frame size: " << last_stack - &x; } else { ARROW_LOG(INFO) << "Depth " << depth << " -> stack: " << (void*)(&x); } ARROW_ASSIGN_OR_RAISE(auto obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_ASSIGN_OR_RAISE(obj, ReturnSomethingBig()); ARROW_UNUSED(obj); if (depth < 10) { RETURN_NOT_OK(PrintStack(depth + 1, &x)); } return Status::OK(); } TEST(ResultTest, StackConsumption) { ASSERT_OK(PrintStack()); } ``` On my machine in debug mode this prints: ``` [ RUN ] ResultTest.StackConsumption /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:842: Depth 0 -> stack: 0x7ffc1d874bdf /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 1 -> stack: 0x7ffc1d87455f -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 2 -> stack: 0x7ffc1d873edf -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 3 -> stack: 0x7ffc1d87385f -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 4 -> stack: 0x7ffc1d8731df -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 5 -> stack: 0x7ffc1d872b5f -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 6 -> stack: 0x7ffc1d8724df -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 7 -> stack: 0x7ffc1d871e5f -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 8 -> stack: 0x7ffc1d8717df -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 9 -> stack: 0x7ffc1d87115f -> frame size: 1664 /home/antoine/arrow/dev/cpp/src/arrow/result_test.cc:839: Depth 10 -> stack: 0x7ffc1d870adf -> frame size: 1664 ``` Ideally the frame size should be not much more than 128 bytes in this example. This matters when doing recursive calls, because stack consumption can be much higher than expected. ### Component(s) C++ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
