You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "LiangliangSui (via GitHub)" <gi...@apache.org> on 2025/12/04 04:10:43 UTC
[PR] perf(c++): improve the serialization performance of arrat/collection [fory]
LiangliangSui opened a new pull request, #2986:
URL: https://github.com/apache/fory/pull/2986
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here.
-->
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
<!-- Describe the details of this PR. -->
improve the serialization performance of arrat/collection
## Related issues
<!--
Is there any related issue? If this PR closes them you say say fix/closes:
- #xxxx0
- #xxxx1
- Fixes #xxxx2
-->
https://github.com/apache/fory/issues/2978
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2986:
URL: https://github.com/apache/fory/pull/2986#discussion_r2588123668
##########
cpp/fory/serialization/array_serializer.h:
##########
@@ -149,14 +155,21 @@ template <size_t N> struct Serializer<std::array<bool, N>> {
static Result<void, Error> write_data(const std::array<bool, N> &arr,
WriteContext &ctx) {
+ // bulk write may write 8 bytes for varint32
+ constexpr size_t max_size = 8 + N;
+ ctx.buffer().Grow(static_cast<uint32_t>(max_size));
+ uint32_t writer_index = ctx.buffer().writer_index();
// Write array length
- ctx.write_varuint32(static_cast<uint32_t>(N));
+ writer_index +=
+ ctx.buffer().PutVarUint32(writer_index, static_cast<uint32_t>(N));
// Write each boolean as a byte (per spec, bool is serialized as int16,
// but for arrays we use packed bytes for efficiency)
for (size_t i = 0; i < N; ++i) {
- ctx.write_uint8(arr[i] ? 1 : 0);
+ ctx.buffer().UnsafePutByte(writer_index + i,
Review Comment:
how about create a local buffer variable outside of the loop
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "LiangliangSui (via GitHub)" <gi...@apache.org>.
LiangliangSui commented on PR #2986:
URL: https://github.com/apache/fory/pull/2986#issuecomment-3611127093
@chaokunyang PTAL
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2986:
URL: https://github.com/apache/fory/pull/2986#discussion_r2588256455
##########
cpp/fory/serialization/array_serializer.h:
##########
@@ -155,21 +155,21 @@ template <size_t N> struct Serializer<std::array<bool, N>> {
static Result<void, Error> write_data(const std::array<bool, N> &arr,
WriteContext &ctx) {
+ Buffer buffer = ctx.buffer();
Review Comment:
change all such code, it's wrong
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2986:
URL: https://github.com/apache/fory/pull/2986#discussion_r2588126173
##########
cpp/fory/serialization/collection_serializer.h:
##########
@@ -835,10 +842,17 @@ template <typename Alloc> struct Serializer<std::vector<bool, Alloc>> {
static inline Result<void, Error>
write_data(const std::vector<bool, Alloc> &vec, WriteContext &ctx) {
- ctx.write_varuint32(static_cast<uint32_t>(vec.size()));
- for (bool value : vec) {
- ctx.write_uint8(value ? 1 : 0);
+ // bulk write may write 8 bytes for varint32
+ size_t max_size = 8 + vec.size();
+ ctx.buffer().Grow(static_cast<uint32_t>(max_size));
+ uint32_t writer_index = ctx.buffer().writer_index();
+ writer_index += ctx.buffer().PutVarUint32(
+ writer_index, static_cast<uint32_t>(vec.size()));
+ for (size_t i = 0; i < vec.size(); ++i) {
+ ctx.buffer().UnsafePutByte(writer_index + i,
Review Comment:
ditto here
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2986:
URL: https://github.com/apache/fory/pull/2986
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2986:
URL: https://github.com/apache/fory/pull/2986#discussion_r2588128186
##########
cpp/fory/serialization/collection_serializer.h:
##########
@@ -544,10 +544,17 @@ struct Serializer<
return Unexpected(
Error::invalid("Vector byte size exceeds uint32_t range"));
}
- ctx.write_varuint32(static_cast<uint32_t>(total_bytes));
+ // bulk write may write 8 bytes for varint32
+ size_t max_size = 8 + total_bytes;
+ ctx.buffer().Grow(static_cast<uint32_t>(max_size));
Review Comment:
4 buffer access, may deserve a local variable
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] perf(c++): improve the serialization performance of array/collection [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2986:
URL: https://github.com/apache/fory/pull/2986#discussion_r2588254554
##########
cpp/fory/serialization/array_serializer.h:
##########
@@ -71,19 +71,19 @@ struct Serializer<
static Result<void, Error> write_data(const std::array<T, N> &arr,
WriteContext &ctx) {
+ Buffer buffer = ctx.buffer();
Review Comment:
```suggestion
Buffer &buffer = ctx.buffer();
```
##########
cpp/fory/serialization/array_serializer.h:
##########
@@ -71,19 +71,19 @@ struct Serializer<
static Result<void, Error> write_data(const std::array<T, N> &arr,
WriteContext &ctx) {
+ Buffer buffer = ctx.buffer();
Review Comment:
```suggestion
Buffer &buffer = ctx.buffer();
```
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org