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
[TIMOB-25941] Android: Optimized HTTPClient download performance #10274
Conversation
- Increased network response buffer size from 4kb to 8kb. - Removed "ondatastream" event's undocumented "blob" property. * Improves performance by avoiding an extra buffer copy. * Note that iOS does not support this undocumented API. - Modified "responseText" property to only create a string when accessed. * Major performance improvement. No longer transcodes per response buffer. * Fixed "responseText" to provide total text downloaded like iOS instead of only the buffered segment's text.
System.arraycopy(data, 0, blobData, 0, size); | ||
|
||
TiBlob blob = TiBlob.blobFromData(blobData, contentType); | ||
callbackData.put("blob", blob); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is a breaking Api change (and should go into 8.0.0) since this is removed. Although, it's hard to see how many people would be using this undocumented event callback property...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. But from searching our repo's and JIRA's history, it doesn't appear to be used. We've discussed it internally in the office and decided to remove it.
Also note that we have a customer that wants a solution to this performance issue before Titanium 8.0.0. You may want to talk to Eric about this.
@@ -245,7 +246,7 @@ private void handleResponse(HttpURLConnection connection) throws IOException | |||
Log.d(TAG, "Content length: " + contentLength, Log.DEBUG_MODE); | |||
int count = 0; | |||
long totalSize = 0; | |||
byte[] buf = new byte[4096]; | |||
byte[] buf = new byte[8192]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract the magic constant as a final static at top so it's easier to tweak the buffer size?
(in fact looking at this file it looks like we have a number of magic constants around buffers/sizes: 512 bytes for progress notifications/entity data buffer; 8MB for blob/file I/O buffer; 512Kb for dumping response to file first rather than keep in-memory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not worth changing to a constant if it's only used in 1 place in the code. It's better to keep it simple.
Yes, there are other place in this class where there is duplication, but that's a refactoring for another day.
FR Passed. An improved performance is seen as compared to 7.3.0 SDK. Studio Ver: 5.1.0.201808080937 |
Generated by 🚫 dangerJS |
JIRA:
https://jira.appcelerator.org/browse/TIMOB-25941
Summary:
blob
from callbackondatastream()
.responseText
property handling only create its string when accessed.responseText
to provide total text downloaded like iOS instead of the buffered response segment's text.responseText
orresponseData
inonload()
callback may provide an incomplete response.Test:
@lokeshchdhry, I recommend that you test this at home. The office network is too congested and download speed varies wildly.