Skip to content

GH-39270: [C++] Avoid creating memory manager instance for every buffer view/copy#39271

Merged
kou merged 3 commits intoapache:mainfrom
kou:cpp-message-decoder-memory-manager
Jan 11, 2024
Merged

GH-39270: [C++] Avoid creating memory manager instance for every buffer view/copy#39271
kou merged 3 commits intoapache:mainfrom
kou:cpp-message-decoder-memory-manager

Conversation

@kou
Copy link
Copy Markdown
Member

@kou kou commented Dec 18, 2023

Rationale for this change

We can use arrow::default_cpu_memory_manager() for default_memory_pool().

What changes are included in this PR?

Check the given pool and use arrow::default_cpu_memory_manager() if it's arrow::default_memory_pool().

This also caches arrow::CPUDevice::memory_manager() result to avoid calling it multiple times. Note that we can avoid creating needless memory manager instance without this. This just avoid calling it multiple times.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not add this optimization to CPUDevice::memory_manager directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I didn't notice it.
I'll do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.
I've updated the PR title.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Jan 9, 2024
kou added 2 commits January 10, 2024 08:47
… in MessageDecoder

We can use `arrow::default_cpu_memory_manager()` for
`default_memory_pool()`.
@kou kou force-pushed the cpp-message-decoder-memory-manager branch from 704f556 to ec38f61 Compare January 9, 2024 23:52
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jan 9, 2024
@kou kou changed the title GH-39270: [C++] Avoid creating needless memory manager instance in MessageDecoder GH-39270: [C++] Avoid creating needless memory manager instance in CPUDevice::memory_manager() Jan 10, 2024
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jan 10, 2024
@pitrou
Copy link
Copy Markdown
Member

pitrou commented Jan 10, 2024

@kou Your latest push is ondoing the main optimization, which is to avoid calling CPUDevice::memory_manager for each buffer view.

@pitrou pitrou self-requested a review January 10, 2024 17:10
@github-actions github-actions bot removed the awaiting changes Awaiting changes label Jan 10, 2024
@kou
Copy link
Copy Markdown
Member Author

kou commented Jan 10, 2024

I thought that reusing the default memory manager for CPU is the main optimization. Caching it as an instance variable is just for simplifying codes.

Anyway, I've added the instance variable again.

@github-actions github-actions bot added the awaiting change review Awaiting change review label Jan 10, 2024
@pitrou pitrou changed the title GH-39270: [C++] Avoid creating needless memory manager instance in CPUDevice::memory_manager() GH-39270: [C++] Avoid creating memory manager instance for every buffer view/copy Jan 11, 2024
@pitrou
Copy link
Copy Markdown
Member

pitrou commented Jan 11, 2024

I thought that reusing the default memory manager for CPU is the main optimization

Only if you're using the default memory manager!

@kou
Copy link
Copy Markdown
Member Author

kou commented Jan 11, 2024

Ah, I didn't care about the case!

@kou kou merged commit 2132cb3 into apache:main Jan 11, 2024
@kou kou deleted the cpp-message-decoder-memory-manager branch January 11, 2024 13:45
@kou kou removed the awaiting change review Awaiting change review label Jan 11, 2024
@conbench-apache-arrow
Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 2132cb3.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

dgreiss pushed a commit to dgreiss/arrow that referenced this pull request Feb 19, 2024
…y buffer view/copy (apache#39271)

### Rationale for this change

We can use `arrow::default_cpu_memory_manager()` for `default_memory_pool()`.

### What changes are included in this PR?

Check the given `pool` and use `arrow::default_cpu_memory_manager()` if it's `arrow::default_memory_pool()`.

This also caches `arrow::CPUDevice::memory_manager()` result to avoid calling it multiple times. Note that we can avoid creating needless memory manager instance without this. This just avoid calling it multiple times.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#39270

Authored-by: Sutou Kouhei <kou@clear-code.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++] Use default_cpu_memory_manager() for the default memory pool in MessageDecoder

2 participants