Repository navigation
Optimize ResStringPool - #4138
IgorEisberg merged 6 commits into
Conversation
|
Just a few tweaks regarding consistency with the rest of the source (like unneeded whitespace). Other than that, this looks like a fine PR. |
Thought about this, I guess it was more about "what if this might be needed elsewhere", plus naming them makes it more clear what they do. I suppose I can inline them, no problem. |
|
Would it be better to move packing functions to ResStringPool or should I just completely inline them? |
It's in the slippery slope territory. It only handles packing 2 integers into 1 long.
I guess it's a style question that doesn't have an objective answer. |
|
|
Oh yeah, I keep forgetting Java has L suffixes too.
Sorry, not following, what other change suggestions? |
Forgot to submit the suggestions lmao. |
Co-authored-by: Igor Eisberg <8811086+IgorEisberg@users.noreply.github.com>
IgorEisberg
left a comment
There was a problem hiding this comment.
This is fine. Tested myself on a large scale to be extra safe.
The failed check can be ignored, GitHub Actions has a stroke.
Added details about performance improvements and library upgrades.
Here are the major changes:
new String(mStrings, offset, length, StandardCharsets.UTF_8)because String has a fast path for decoding UTF-8 strings. UTF-8 malformed checks were also moved to an if statement.new String()usesCodingErrorAction.REPLACEand checking it is trivial. I also moved bound checks to an if case at the top of the function to avoid paying for thrown exceptions.I also thought of inlining
getStyle()insidegetText()to avoid extra allocations, but from what I tested, not many APKs benefit from it. Maybe the APKs I tested weren't good candidates to benchmark this. Anyway, it's worth noting thatgetStyle()returning an array isn't the best possible behavior.I'm a bit skeptical about keeping index-to-string and string-to-index caches in memory, but seeing how getString() is used, it seems like getString() may be called for the same indexes multiple times. Correct me if I'm wrong, in which case I'll get rid of the cache.
Here's before and after in memory usage for the Samsung APK I use for benchmarks: