Skip to content

GH-47774: [C++] Force-inlince Status::~Status() to improve reading performance - #50749

Open
zhf999 wants to merge 1 commit into
apache:mainfrom
zhf999:status-destruction
Open

GH-47774: [C++] Force-inlince Status::~Status() to improve reading performance#50749
zhf999 wants to merge 1 commit into
apache:mainfrom
zhf999:status-destruction

Conversation

@zhf999

@zhf999 zhf999 commented Jul 31, 2026

Copy link
Copy Markdown

GH-47774: [C++] Force-inline Status::~Status to improve read performance

Rationale for this change

Status is returned by nearly every API on hot paths (e.g. IPC/Parquet reading), so its destructor runs extremely frequently. The destructor body is already optimized for the common success case: it only checks state_ != NULL (with ARROW_PREDICT_FALSE) and returns immediately for an OK status, delegating the rare error cleanup to the out-of-line DeleteState().

However, without an explicit inlining hint, some compilers/optimization levels may not inline this destructor, turning the trivial state_ == NULL fast path into a real function call at every call site. Forcing it inline removes this call overhead on hot read paths and improves read throughput.

In our perf test (reads a parquet file of 6.7GB), Status::~Status cost about 20 seconds, as the following flamegraph shows:
image

After inlining Status::~Status, the hotspot disappeared. End-to-end latency was also reduced by 20 seconds, as expected.

image

What changes are included in this PR?

  • Annotate Status::~Status() in cpp/src/arrow/status.h with ARROW_FORCE_INLINE (__attribute__((always_inline)) inline on GCC/Clang, __forceinline on MSVC), so the cheap null-check fast path is always inlined while the cold error path still goes through the non-inlined DeleteState().

Are these changes tested?

Yes, by existing tests. This change does not alter any behavior of Status; the existing Status unit tests and the full C++ test suite cover it. The performance improvement can be observed with the existing read-path benchmarks.

Are there any user-facing changes?

No. This is an internal performance optimization with no API or behavior change.

Copilot AI review requested due to automatic review settings July 31, 2026 06:31
@zhf999
zhf999 requested a review from pitrou as a code owner July 31, 2026 06:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #47774 has been automatically assigned in GitHub to PR creator.

@HuaHuaY

HuaHuaY commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@ursabot please benchmark lang=C++

@rok

rok commented Jul 31, 2026

Copy link
Copy Markdown
Member

Benchmark runs are scheduled for commit c445460. Watch https://buildkite.com/apache-arrow and https://conbench.arrow-dev.org for updates. A comment will be posted here when the runs are complete.

@HuaHuaY

HuaHuaY commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This PR looks interesting. I call the bot to run the benchmark and let's see whether there's a significant impact.

@conbench-apache-arrow

Copy link
Copy Markdown

Thanks for your patience. Conbench analyzed the 4 benchmarking runs that have been run so far on PR commit c445460.

There were 35 benchmark results indicating a performance regression:

The full Conbench report has more details.

@conbench-apache-arrow

Copy link
Copy Markdown

Thanks for your patience. Conbench analyzed the 4 benchmarking runs that have been run so far on PR commit c445460.

There were 35 benchmark results indicating a performance regression:

The full Conbench report has more details.

@conbench-apache-arrow

Copy link
Copy Markdown

Thanks for your patience. Conbench analyzed the 4 benchmarking runs that have been run so far on PR commit c445460.

There were 35 benchmark results indicating a performance regression:

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants