Skip to content
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

Do not create String instances in 'Strings' methods accepting StringBuilder #22907

Merged
merged 1 commit into from
Feb 23, 2017

Conversation

sabi0
Copy link
Contributor

@sabi0 sabi0 commented Feb 1, 2017

Imagine you are doing something like this:

StringBuilder sb = new StringBuilder();
// ... adding some heavy data to 'sb'
sb.append("indices[");
Strings.arrayToDelimitedString(indices, ",", sb);
sb.append("], ");
sb.append("types[");
Strings.arrayToDelimitedString(types, ",", sb);
sb.append("]");

And before you know it, you've just allocated two extra 5 MB String instances on the heap.

@elasticmachine
Copy link
Collaborator

Can one of the admins verify this patch?

@@ -90,12 +90,12 @@ public void shutdown() throws Exception {
public void testCorsConfig() {
final Set<String> methods = new HashSet<>(Arrays.asList("get", "options", "post"));
final Set<String> headers = new HashSet<>(Arrays.asList("Content-Type", "Content-Length"));
final String suffix = randomBoolean() ? " " : ""; // sometimes have a leading whitespace between comma delimited elements
final String prefix = randomBoolean() ? " " : ""; // sometimes have a leading whitespace between comma delimited elements
Copy link
Member

Choose a reason for hiding this comment

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

Can you please undo this unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value is passed as 'prefix' parameter to the collectionToDelimitedString(coll, delim, prefix, suffix).
And since that method was affected by this change I thought it might be a good idea to also eliminate this possible source of confusion.

But sure, I'll undo it tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a good change and not completely unrelated. Why undo it @rjernst ?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with it, given the explanation. I only saw that it seemed to be a variable name change that was unnecessary.

@rjernst
Copy link
Member

rjernst commented Feb 2, 2017

@elasticmachine test this please

@rjernst
Copy link
Member

rjernst commented Feb 3, 2017

@elasticmachine retest this please, just once, please please please

@sabi0
Copy link
Contributor Author

sabi0 commented Feb 7, 2017

The build was failing due to some unresolvable dependency. I didn't touch any Gradle files though.
Am I expected to do something about that? (rebase the branch?)

@rjernst
Copy link
Member

rjernst commented Feb 7, 2017

@sabi0 We've had issues with our PR CI system. I'll try it once more, otherwise I will run tests manually.

@elasticmachine test this please

@sabi0
Copy link
Contributor Author

sabi0 commented Feb 23, 2017

If your CI is back to normal would you mind pulling this in?

@rjernst
Copy link
Member

rjernst commented Feb 23, 2017

@sabi0 I'm sorry I lost track of this! I just tested and it is good. I will merge now.

@rjernst rjernst merged commit 09b3c7f into elastic:master Feb 23, 2017
@rjernst
Copy link
Member

rjernst commented Feb 23, 2017

Thanks @sabi0!

@sabi0 sabi0 deleted the arrayToDelimitedString-fix branch February 24, 2017 09:07
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 24, 2017
* master: (54 commits)
  Keep the pipeline handler queue small initially
  Do not create String instances in 'Strings' methods accepting StringBuilder (elastic#22907)
  Tests: fix AwsS3ServiceImplTests
  Remove abstract InternalMetricsAggregation class (elastic#23326)
  Add BulkRequest support to High Level Rest client (elastic#23312)
  Wrap getCredentials() in a doPrivileged() block (elastic#23297)
  Respect promises on pipelined responses
  Align REST specs for HEAD requests
  Remove unnecessary result sorting in SearchPhaseController (elastic#23321)
  Fix SamplerAggregatorTests to have stable and predictable docIds
  Tests: Ensure multi node integ tests wait on first node
  Relocate a comment in HttpPipeliningHandler
  Add comments to HttpPipeliningHandler
  [TEST] Fix incorrect test cluster name in cluster health doc tests
  Build: Change location in zip of license and notice inclusion for plugins (elastic#23316)
  Script: Fix value of `ctx._now` to be current epoch time in milliseconds (elastic#23175)
  Build: Rework integ test setup and shutdown to ensure stop runs when desired (elastic#23304)
  Handle long overflow when adding paths' totals
  Don't set local node on cluster state used for node join validation (elastic#23311)
  Ensure that releasing listener is called
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants