Skip to content

Increase StreamUtils.BUFFER_SIZE to 8192 #28965

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

Closed

Conversation

kilink
Copy link
Contributor

@kilink kilink commented Aug 15, 2022

This aligns the buffer size used in StreamUtils with the buffer sized
used throughout the JDK (see InputStream, BufferedInputStream, Files).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 15, 2022
This aligns the buffer size used in StreamUtils with the buffer sizes
used throughout the JDK (see InputStream, BufferedInputStream, Files).
@kilink
Copy link
Contributor Author

kilink commented Aug 15, 2022

FYI, it's also the buffer size used in Guava and Apache Commons.

@kilink kilink force-pushed the increase-stream-utils-buffer-size branch from b6ea71b to 9c4e3df Compare August 15, 2022 23:18
@@ -83,7 +83,7 @@ public static String copyToString(@Nullable InputStream in, Charset charset) thr
return "";
}

StringBuilder out = new StringBuilder(BUFFER_SIZE);
StringBuilder out = new StringBuilder();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning for using the default here, is that for any output less than BUFFER_SIZE, we end up over-allocating by specifying this value. If we use the default, and the first read fills the buffer, we will resize to BUFFER_SIZE immediately anyway when we write to the StringBuilder.

@bclozel bclozel self-assigned this Sep 9, 2022
@bclozel bclozel added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 9, 2022
@bclozel bclozel added this to the 6.0.0-M6 milestone Sep 9, 2022
@bclozel bclozel closed this in cdb38e8 Sep 9, 2022
@bclozel
Copy link
Member

bclozel commented Sep 9, 2022

Thanks for your first contribution @kilink , this will be in the next 6.0.0 milestone.

@kilink kilink deleted the increase-stream-utils-buffer-size branch March 15, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants