Skip to content

ARROW-8022: [C++] Add static and small vector implementations#10915

Closed
pitrou wants to merge 17 commits into
apache:masterfrom
pitrou:ARROW-8022-small-vector
Closed

ARROW-8022: [C++] Add static and small vector implementations#10915
pitrou wants to merge 17 commits into
apache:masterfrom
pitrou:ARROW-8022-small-vector

Conversation

@pitrou

@pitrou pitrou commented Aug 11, 2021

Copy link
Copy Markdown
Member

No description provided.

@github-actions

Copy link
Copy Markdown

@pitrou

pitrou commented Aug 11, 2021

Copy link
Copy Markdown
Member Author

Some operations are not yet implemented: erase, insert...

@pitrou pitrou requested a review from bkietz August 11, 2021 16:57
@pitrou

pitrou commented Aug 11, 2021

Copy link
Copy Markdown
Member Author

@ursabot please benchmark

@ursabot

ursabot commented Aug 11, 2021

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = e544927 and contender = eef6764ec58c823c98ad1df9072039c7e04f9c4e. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Failed ⬇️0.78% ⬆️0.78%] ursa-i9-9960x
[Finished ⬇️0.77% ⬆️0.38%] ursa-thinkcentre-m75q
Supported benchmarks:
ursa-i9-9960x: langs = Python, R, JavaScript
ursa-thinkcentre-m75q: langs = C++, Java
ec2-t3-xlarge-us-east-2: cloud = True

@pitrou pitrou force-pushed the ARROW-8022-small-vector branch 6 times, most recently from 57c3c52 to a97521c Compare August 12, 2021 09:02
Comment thread cpp/src/arrow/util/small_vector.h Outdated
Comment thread cpp/src/arrow/util/small_vector.h Outdated
Comment thread cpp/src/arrow/util/small_vector.h Outdated
@pitrou pitrou force-pushed the ARROW-8022-small-vector branch from f7c9dba to 9a1f2f0 Compare August 16, 2021 11:41
Comment thread cpp/src/arrow/util/small_vector.h Outdated
Comment thread cpp/src/arrow/util/small_vector.h Outdated
Comment thread cpp/src/arrow/util/small_vector.h Outdated
@pitrou pitrou force-pushed the ARROW-8022-small-vector branch from 9a1f2f0 to b9a02e3 Compare August 17, 2021 14:09
@pitrou

pitrou commented Aug 17, 2021

Copy link
Copy Markdown
Member Author

@pitrou pitrou marked this pull request as ready for review August 17, 2021 18:26
@pitrou pitrou requested a review from bkietz August 17, 2021 18:26
Comment thread cpp/src/arrow/util/small_vector_benchmark.cc Outdated
Comment thread cpp/src/arrow/util/small_vector.h Outdated
@pitrou pitrou force-pushed the ARROW-8022-small-vector branch from 4c13a78 to 6e61e29 Compare August 18, 2021 08:23
@pitrou pitrou requested a review from bkietz August 18, 2021 11:45
@pitrou

pitrou commented Aug 18, 2021

Copy link
Copy Markdown
Member Author

@ursabot please benchmark

@ursabot

ursabot commented Aug 18, 2021

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = 973dbae and contender = afc3b92. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.73% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.14% ⬆️0.28%] ursa-thinkcentre-m75q
Supported benchmarks:
ursa-i9-9960x: langs = Python, R, JavaScript
ursa-thinkcentre-m75q: langs = C++, Java
ec2-t3-xlarge-us-east-2: cloud = True

@bkietz bkietz left a comment

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.

just a few more nits

Comment thread cpp/src/arrow/util/small_vector.h Outdated
Comment thread cpp/src/arrow/util/small_vector.h
Comment thread cpp/src/arrow/util/small_vector.h
@pitrou pitrou force-pushed the ARROW-8022-small-vector branch 2 times, most recently from 04de50a to 58ad05e Compare August 23, 2021 16:07
@pitrou

pitrou commented Aug 23, 2021

Copy link
Copy Markdown
Member Author

I added a AlignedStorage facility. @bkietz Can you take a look again?

@pitrou pitrou force-pushed the ARROW-8022-small-vector branch from 58ad05e to 6b48d23 Compare August 23, 2021 17:20
@pitrou pitrou requested a review from bkietz August 23, 2021 17:26

@bkietz bkietz left a comment

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.

Two nits. I think this is good to go

Thanks for doing this!

Comment on lines +295 to +299
storage_.bump_size(count);
auto* p = storage_.storage_ptr();
for (size_t i = 0; i < count; ++i) {
p[i].construct(value);
}

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.

I think we can reuse resize here

Suggested change
storage_.bump_size(count);
auto* p = storage_.storage_ptr();
for (size_t i = 0; i < count; ++i) {
p[i].construct(value);
}
resize(count, value);

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.

Same answer as below. Given that this code is short enough, I think it's reasonable to keep it as is.

}

template <typename InputIt>
void assign_by_copying(size_t n, InputIt src) {

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.

I think all four of these could be collapsed into a single SmallVectorImpl::assign(It begin, It end) method without overhead. Then we'd write

  StaticVectorImpl& operator=(std::vector<T>&& other) noexcept {
    assign(std::make_move_iterator(other.begin()), std::make_move_iterator(other.end()));
    return *this;
  }

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.

Ideally without overhead, but compilers do not always do their best, which is why I've avoided generalization here.

@pitrou pitrou closed this in 257d0aa Aug 26, 2021
@pitrou pitrou deleted the ARROW-8022-small-vector branch August 26, 2021 12:03
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.

3 participants