Skip to content

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

Open
@abonie

Description

@abonie

Seems like there is a lot we could do to improve perf of string interpolation. One good example is fsharp/fslang-suggestions#1108, but also some low hanging fruits to start with could be unfolding compile time constants, e.g.:

[<Literal>]
let x = "hello"

[<Literal>]
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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions