HaxeFoundation / HaxeFoundation/haxe
JVM target: slow string append
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```
class ProblemAppendToSlow {
public static function main(): Void {
var o: String = "";
o += 'P3\n';
o += '255\n';
for(iy in 0...10000) {
trace('line=${iy}');
for(ix in 0...100) {
o += '$ix $ix $ix\n';
}
}
trace(o.length); // to not let "o" get optimized away somehow
}
}
```
haxe version: 4.2.3
compiled with
`haxe --jvm a.jar ProblemAppendToSlow.hx --main ProblemAppendToSlow.hx && java -jar ./a.jar`
results in a program where the trace debug output slows down.
I would expect that it doesn't slow down that much. The reason is probably that the compiler isn't using a StringBuilder as the java compiler does.
Contributor guide
Research direction
Start by running the provided ProblemAppendToSlow.hx reproduction with the documented Haxe JVM command and confirm the slowdown. Then trace the JVM target's handling of the repeated `o +=` expressions, comparing the generated behavior with the reported StringBuilder expectation. Done means the reproduction no longer suffers from the reported string-append slowdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100