Skip to content

Fix issue with large base_64 JSON (Request or Response)#1411

Merged
cortinico merged 3 commits into
ChuckerTeam:mainfrom
Khudoyshukur:fix/large_base_64
Jul 4, 2025
Merged

Fix issue with large base_64 JSON (Request or Response)#1411
cortinico merged 3 commits into
ChuckerTeam:mainfrom
Khudoyshukur:fix/large_base_64

Conversation

@Khudoyshukur

Copy link
Copy Markdown
Contributor

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


@Khudoyshukur Khudoyshukur requested a review from a team as a code owner July 2, 2025 06:59
@cortinico

Copy link
Copy Markdown
Member

Could you fix the CI @Khudoyshukur

@Khudoyshukur

Copy link
Copy Markdown
Contributor Author

@cortinico Fixed, can you please check one more time

@Khudoyshukur

Copy link
Copy Markdown
Contributor Author
image

@cortinico
I think there has been a network issue here. I did not touch any gradle related files

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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Khudoyshukur Khudoyshukur Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shivanandyadav11

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?

@cortinico cortinico left a comment

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.

That's great thank you very much for sending this over!

@cortinico cortinico enabled auto-merge (squash) July 4, 2025 22:30
@cortinico cortinico merged commit f9ec3fd into ChuckerTeam:main Jul 4, 2025
6 of 7 checks passed
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.

3 participants