dotnet / dotnet/fsharp

Optimization for string interpolation - simple scenarios: unfolding constants and lowering to concatenation

Open
#16,247 6 comments 4 reactions 1 assignee Claimed by @abonie View on GitHub
Area-Compiler-Optimization Feature Improvement Theme-Performance
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Seems like there is a lot we could do to improve perf of string interpolation. One good example is https://github.com/fsharp/fslang-suggestions/issues/1108, but also some low hanging fruits to start with could be unfolding compile time constants, e.g.:
```fsharp
[]
let x = "hello"

[]
let y = "world"

let z = $"{x} {y}!"
```
in the above, the last line could be lowered to `let z = "hello world!"`

Another one could be lowering to `System.String.Concat` when it applies, e.g. `let f (x: string) (y: string) = $"{x},{y}."` could be rewritten as `let f (x: string) (y: string) = System.String.Concat(x, ",", y, ".")`, because we know that all expression holes are filled with objects of type string and there are at most 4 pieces to concatenate.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.