Replies: 1 comment 7 replies
-
Note that in optimizing this function for calls with large
Same as above. If you don't know for sure that
If moving that out of the loop gives that much performance increase, then you probably have an issue with functions not being inlined. Maybe these changes could be made safer by only using the resize behavior when the buffer being added is large. |
Beta Was this translation helpful? Give feedback.
-
Use case: Json object stores big numeric array (>1M array of floats). Need to serialize Json to some binary format (say, msgpack), send over network, and deserialize at the other end.
Configuration: MSVC 2019, Win10, Release build.
Observations:
I did two simple modifications:
In binary_reader::get_binary() method I resized result before for() loop, changed push_back() to [] assignment, and replaced unexpect_eof() call to comparison to eof():
This mod gives ~50 times performance increase (notably, moving unexpect_eof() out of loop alone gives 2x times performance increase).
Another mod is in output_vector_adapter::write_characters() method: instead of std::copy(s, s + length, std::back_inserter(v)), I did this:
This also gives ~30 times performance increase.
I believe that systematic optimizations of all places where arrays/vectors of scalar types are handled, will give tremendous performance increase, when per-element assignment/copy operations will be replaced with bulk memory copy operations.
Beta Was this translation helpful? Give feedback.
All reactions