-
Couldn't load subscription status.
- Fork 38.8k
SPR-15762: improve performance of ContentCachingRequestWrapper #1474
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
Conversation
|
@xnslong Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
|
@xnslong Thank you for signing the Contributor License Agreement! |
|
@xnslong can you please create a Jira issue for this change? |
|
I've done that for you, check the update on the Jira issue |
|
@snicoll Sorry for the late reply, I checked the benchmark on the issue, and I found there is mistake in my code. After it is fixed, it performs very differently. Would you please take a look? |
|
My mistake is fixed now |
|
Merged with 4d0800f |
|
Thanks! @bclozel I checked the merge commit in last comment, but I found some code may cause problem. Show as the following @Override
public int read(final byte[] b) throws IOException {
int count = super.read(b);
// the following code may cause problem
if (!this.overflow && count > 0) {
if (contentCacheLimit != null && cachedContent.size() == contentCacheLimit) {
this.overflow = true;
handleContentOverflow(contentCacheLimit);
} else {
int sizeToCache = contentCacheLimit == null || count + cachedContent.size() < CacheLimit
? count
: contentCacheLimit - cachedContent.size();
cachedContent.write(b, 0, sizeToCache);
if (sizeToCache < count) {
this.overflow = true;
handleContentOverflow(contentCacheLimit);
}
}
}
return count;
}The I think it may be good not to override this method, because the |
The
ContentCachingInputStreamclass has only implemented theint read()method of the stream, let the correspondingread(byte[], int, int)method inherit from theInputStreamclass.However, reading a few bytes from an
InputStreamwith a loop call of theint read()method and a call with theread(byte[], int, int)method differs a lot. The latter method is much faster than the former method. My code and result for this comparison are listed bellow.Finally, I got the following result on my machine.