-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Reduce memory allocations in Java #20243
Comments
Can you clarify - are you using Java or Java Lite on Android, @ibradwan ? |
Java Lite. |
re: re-using builders My take for this one is that even though it is supposed to be safe ( One might consider doing this iff the performance is extremely critical. |
Well the concurreny risk is there regardless, but I see your point that reusing the objects will inherently increase the chances of this happening. However, experienced developers working in low-end or high-scale enviroments would definitely perfer having the option to save up memory and GC time while knowing that they should implement the required measures to protect against concurrency issues (e.g., using builder pools per concurrent context/thread). |
Doesn't |
@shaod2 When I was looking into this, I found some very old posts mentioning that it's not safe to do so. I also didn't find any note indicating that this has changed since then. Anyway, if it's safe to do so, this would solve half of the problem, which is creating builders for every message. Speaking of the other problem, is there a way to skip building the message object and directly emit the serialized byte array? |
@shaod2 Could you please confirm that reusing builders through the |
Currently I don't think there is way to get the serialized byte array from builder directly.. but it's an interesting idea to be evaluated. I've already put an agenda to talk about this internally. Again, whether it's |
Okay thanks for your reply. Will give it a shot and test it out and see how things go. Meanwhile, please keep us updated if there's anything new. P.S. I was actually referring to 'clear()'. |
What language does this apply to?
Java
Describe the problem you are trying to solve.
Memory allocations could be optimized through using reusable objects. Right now, every message requires two objects, a builder and a message. Those objects aren't reusable, which makes it inefficient when serializing a lot of objects especially on limited-resources devices like low-end Android devices. Moreover, the excessive allocations of objects increase the garbage collection frequency which has its impact on the overall process perf.
Describe the solution you'd like
Two suggestions:
The text was updated successfully, but these errors were encountered: