String vs byte array, Performance

后端 未结 2 1895
一生所求
一生所求 2021-02-08 07:03

(This post is regarding High Frequency type programming)

I recently saw on a forum (I think they were discussing Java) that if you have to parse a lot of string data its

2条回答
  •  花落未央
    2021-02-08 07:36

    There are lots of other reasons to use byte[] or char* instead of Strings for HFT. Strings consists of 16-bit char in Java and are immutable. byte[] or ByteBuffer are easily recycled, have good cache locatity, can be off the heap (direct) saving a copy, avoiding character encoders. This all assumes you are using ASCII data.

    char* or ByteBuffers can also be mapped to network adapters to save another copy. (With some fiddling for ByteBuffers)

    In HFT you are rarely dealing with large amounts of data at once. Ideally you want to be processing data as soon as it comes down the Socket. i.e. one packet at a time. (about 1.5 KB)

提交回复
热议问题