Fix issue with large base_64 JSON (Request or Response)#1411
Merged
Conversation
Member
|
Could you fix the CI @Khudoyshukur |
Contributor
Author
|
@cortinico Fixed, can you please check one more time |
Contributor
Author
@cortinico |
Comment on lines
+543
to
+566
| private fun SpannableStringBuilder.spannableChunked(size: Int): List<SpannableStringBuilder> { | ||
| val result = mutableListOf<SpannableStringBuilder>() | ||
| var startIndex = 0 | ||
| while (startIndex < length) { | ||
| val endIndex = (startIndex + size).coerceAtMost(length) | ||
| val chunk = SpannableStringBuilder(subSequence(startIndex, endIndex)) | ||
|
|
||
| val spans = this.getSpans<Any>(startIndex, endIndex) | ||
| for (span in spans) { | ||
| val start = this.getSpanStart(span) | ||
| val end = this.getSpanEnd(span) | ||
| val flags = this.getSpanFlags(span) | ||
|
|
||
| val newStart = if (start < startIndex) 0 else start - startIndex | ||
| val newEnd = if (end > endIndex) chunk.length else end - startIndex | ||
|
|
||
| chunk.setSpan(span, newStart, newEnd, flags) | ||
| } | ||
| result.add(chunk) | ||
|
|
||
| startIndex += size | ||
| } | ||
| return result | ||
| } |
Contributor
There was a problem hiding this comment.
I think this extension function would be a great candidate for a dedicated Utils class/object. Extracting it there will make it easier to locate and write unit tests for it.
Contributor
Author
There was a problem hiding this comment.
I could not find predefined Utils class. So created one with a name 'SpannableStringExtension'.
And I wrote few unit tests for the function.
Can you please check it again?
shivanandyadav11
approved these changes
Jul 4, 2025
cortinico
approved these changes
Jul 4, 2025
cortinico
left a comment
Member
There was a problem hiding this comment.
That's great thank you very much for sending this over!
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Large base64 Json loading issue
2025-07-02.11.45.38.mp4
After the fix applied
2025-07-02.11.45.19.mp4
📄 Context
Actually I encountered to this issue at work while using chucker
📝 Changes
Actually currently we are using recycler view to render the JSON. We are getting each line of the json (using line breaks like '\n') and giving each line to the recycler view.
The problem is that when we are working with large base64 JSONs, it does not contain line break ('\n') chars. It means that recycler view should render huge amount of text on the screen. This is causing ANR.
What I changed:
I checked each line length. If it exceeds some threshold (i put 500). Then I split this line into chunks preserving the span style of the line. With this, the recycler view item will get at most 500 chars to render, not whole base64 string
This is a bug-fix, and I think it does not affect the behavior of the app. So, i did not included this in CHANGELOG
📎 Related PR
No
🚫 Breaking
No
🛠️ How to test
For testing purposes, i added one more request to sample app to test large base64
⏱️ Next steps