eventuate-foundation / eventuate-messaging-kafka

Other
15 stars 11 forks source link

Investigate first figuring out how many messages will fit, and then allocating a buffer large enough #18

Open cer opened 4 years ago

cer commented 4 years ago

Currently, the buffer is dynamically reallocated. An alternative approach is

  1. Figure out how many messages will fit in the buffer
  2. Allocate a big enough buffer
  3. Deserialize the messages into it

The trick is to perform step 1 without allocating memory, .e.g calculating the size in bytes of a String without calling getBytes(encoding). Note, it would be ok to overestimate the needed size, e.g. assume each char in string needs 2 bytes.

This needs research:, e.g. https://stackoverflow.com/questions/19852460/get-size-of-string-w-encoding-in-bytes-without-converting-to-byte