-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove .clone() for ByteString #18
Comments
The call to Unfortunately, PMD considers your suggestion as a security problem: I would merge a PR that removes the |
OK I understand, I will submit a pull request tomorrow or so. Thanks! |
I just had a look at how to configure PMD and it seems to be quite tricky to exclude a rule for a specific file or even method. I was hoping for some kind of annotation but that's not how it works apparently. I'm afraid I won't have the time to look into that unfortunately. Since the encoder is hardwired to that specific ByteString class (and not an interface) I also can't just extend or copy a modified version into my codebase as a quick fix. With an Any suggestion? |
I'll take care about that :-) |
Solution: remove the `clone()` Fixes #18 The call to `clone()` was originally introduced to pass the PMD checks. However, the PMD checks seem to be broken for a while, so we can safely change this. Additionally, we add a test that ensures that cloning will not be re-introduced later.
Thanks! :)
|
Hope to find the time for an official release (also on maven central) today |
My use case is to encode big byte strings (which are then tagged as typed arrays), possibly up to 100MiB. I haven't profiled it yet, but from previous experience I can smell that the ByteString class will be one source of bottlenecks due to its use of array cloning within the constructor and also in getBytes(). In the ByteStringEncoder the getBytes() method is called and there is absolutely no reason to make a copy here. For the constructor, well, I would put more responsibilty into the user's hands and explicitly say in the javadoc that no copy is made, so the user has to make one himself if he wants to further use the byte array.
Removing the cloning operations will not only reduce memory usage spikes but also remove the time it would take to make the clone and also the effort that the garbage collector would have.
The text was updated successfully, but these errors were encountered: