FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Reduce size of buffer, stringBuffer and tape. by ZhaiMo15 · Pull Request #42 · simdjson/simdjson-java · GitHub

Reduce size of buffer, stringBuffer and tape. - #42

Open
ZhaiMo15 wants to merge 1 commit into
simdjson:mainfrom
ZhaiMo15:ReduceBufferSize
Open

Reduce size of buffer, stringBuffer and tape.#42
ZhaiMo15 wants to merge 1 commit into
simdjson:mainfrom
ZhaiMo15:ReduceBufferSize

Conversation

Copy link
Copy Markdown

In class JsonValue, the default size of buffer and stringBuffer, as well as long[] tape in class Tape, is 34M.
But in practice it's not necessary.
This patch reduce the size of them from 34M to its actual size.

Copy link
Copy Markdown
Author

I believe in future, the JsonValue might be deep copied, thus the size of byte[] and long[] is important.

ZhaiMo15 force-pushed the ReduceBufferSize branch 2 times, most recently from e72bac3 to 9fcfa59 Compare April 16, 2024 09:50
In class JsonValue, the default size of buffer and stringBuffer, as
well as long[] tape in class Tape, is 34M.
But in practice it's not necessary.
This patch reduce the size of them from 34M to its actual size.
private byte[] padIfNeeded(byte[] buffer, int len) {
if (buffer.length - len < PADDING) {
if (buffer.length - len < PADDING && len < capacity) {
byte[] paddedBuffer = new byte[len + PADDING];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The reason for maintaining the paddedBuffer all the time, regardless of whether it is necessary or not, is to avoid allocations on hot paths. However, I see at least two issues with padding in general. Firstly, it requires adding this extra branch. Secondly, it complicates the API: on one hand, the user doesn't need to be aware of it, but on the other hand, if they want to achieve the best performance, they should pad the input. Therefore, I've been considering removing the need for padding altogether. It should be possible, although I haven't thoroughly researched this topic.

To summarize: I'd start by verifying if removing the padding is possible. If so, I'd remove it and test the performance of the parser. If there is no regression compared to the current version with padding, we have a win-win situation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think by design, the padding is 64 bytes. However, the 'paddedBuffer' is 34MB, that's such a waste. I'm just change the padding size to 64 bytes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I agree with you that this is a waste. However, in your approach, you are potentially allocating a new array on every call of the parse method, which can be costly.

I've been working on removing the padding entirely. It's a bit complicated, but we will see if it is feasible. I'll report back.


int stringBufferLen = stringParser.getStringBufferIdx();
byte[] newStringBuffer = new byte[stringBufferLen];
System.arraycopy(stringBuffer, 0, newStringBuffer, 0, stringBufferLen);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is this change related to #36? I'm asking because I'm a bit concerned that we need another allocation on the parsing path.

ZhaiMo15 Apr 29, 2024
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes. I think there must be an allocation somewhere, if we want to save the information of "old" data.

ZhaiMo15 Apr 29, 2024
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

And as I mentioned above, the default size of buffer and stringBuffer, as well as long[] tape in class Tape, is 34M. If we allocated 34M * 3 for each element, the cost is way too much.

ZhaiMo15 closed this Jun 11, 2024
ZhaiMo15 deleted the ReduceBufferSize branch June 11, 2024 03:05
ZhaiMo15 restored the ReduceBufferSize branch June 11, 2024 03:25
ZhaiMo15 reopened this Jun 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL