ion-java icon indicating copy to clipboard operation
ion-java copied to clipboard

Consider writing directly to the backing array in WriteBuffer

Open popematt opened this issue 2 years ago • 0 comments

As an optimization, we could go into the fallback loop branch if remaining() < numBytes, then in the short branches we can write directly into the buffer rather than repetitively calling writeByte, which requires some redundant logic. See e.g. writeUInt64 vs writeUInt64Slow.

Originally posted by @tgregg in https://github.com/amazon-ion/ion-java/pull/609#discussion_r1362648083

As an optimization, we could have fast/slow variants of this too, where we do the current technique when remaining() < numBytes, and otherwise we just write directly into the underlying array.

Originally posted by @tgregg in https://github.com/amazon-ion/ion-java/pull/610#discussion_r1362698735

This might be a good candidate for a method in WriteBuffer. I have a feeling it will ultimately benefit from an optimization that writes directly into the WriteBuffer's array if enough space is available.

Originally posted by @tgregg in https://github.com/amazon-ion/ion-java/pull/612#discussion_r1362739224

popematt avatar Oct 17 '23 19:10 popematt