Skip to content

Optimize string concatenation #447

@bertysentry

Description

@bertysentry

Problem

Concatenations of strings may not be optimized, especially when they are chained, like in the example below:

197 : DEREFERENCE, 10, false, false
198 : DEREF_ARRAY
199 : PUSH_STRING, ";48;5;"
200 : DEREFERENCE, 4, true, true
201 : DEREFERENCE, 11, false, false
202 : DEREF_ARRAY
203 : PUSH_STRING, "m"
204 : CONCAT
205 : CONCAT
206 : CONCAT
207 : CONCAT
208 : CONCAT

Specifications

Replace stringed CONCAT tuples with a single call that says CONCAT n, where n is the number of items from the stack to concatenate. Then use a StringBuilder to concatenate all elements.

Add benchmarks (with JMH) for various string concatenations scenarios:

  • "constant" "constant" "constant" "constant"
  • string1 "constant" string2 "constant"
  • string1 string2 string3 string4

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions