Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Reduce StringEscapeHelper escape and unescape allocations#46

Merged
iconara merged 1 commit intoburtcorp:masterfrom
gatling:string-escape-helper-optim
Jun 7, 2019
Merged

Reduce StringEscapeHelper escape and unescape allocations#46
iconara merged 1 commit intoburtcorp:masterfrom
gatling:string-escape-helper-optim

Conversation

@slandelle
Copy link
Contributor

Motivation:

  • StringEscapeHelper allocates StringBuilder of default size (16) so there's a good chance it will either be too large, or too small and reallocate underlying char array.
  • escaped always allocate StringBuilder, even when there's nothing to escape in the input String.

Modifications:

  • Set StringBuilder initial capacity
  • lazy allocate escape's StringBuilder

Result:

Less allocations.

Motivation:

* StringEscapeHelper allocates StringBuilder of default size (16) so there's a good chance it will either be too large, or too small and reallocate underlying char array.
* escaped always allocate StringBuilder, even when there's nothing to escape in the input String.

Modifications:

* Set StringBuilder initial capacity
* lazy allocate escape's StringBuilder

Result:

Less allocations.
@slandelle
Copy link
Contributor Author

ping @iconara

Copy link
Collaborator

@iconara iconara left a comment

Choose a reason for hiding this comment

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

LGTM

@iconara iconara merged commit 8f007ca into burtcorp:master Jun 7, 2019
@slandelle slandelle deleted the string-escape-helper-optim branch June 7, 2019 08:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants