Skip to content

Conversation

@Numpsy
Copy link
Contributor

@Numpsy Numpsy commented Aug 17, 2025

Just a thought I had after running a run of FSharpLint over one of my projects thought the Visual Studio memory profiler. It's quite trivial in the overall schema of things, but in case anyone is interested.

I noticed that charListToString was creating quite a large number of strings:

Screenshot 2025-08-10 224138

And I wondered if String.Create could be used to reduce the number of temporary strings. Doing so got

Screenshot 2025-08-11 005042

The actual amounts of memory here are rather small compared to total memory because the strings are tine -

Before

| Method      | Mean    | Error    | StdDev   | Gen0        | Gen1       | Gen2      | Allocated  |
|------------ |--------:|---------:|---------:|------------:|-----------:|----------:|-----------:|
| LintProject | 3.983 s | 0.1033 s | 0.2964 s | 167000.0000 | 22000.0000 | 1000.0000 | 1008.65 MB |

After

| Method      | Mean    | Error    | StdDev   | Gen0        | Gen1       | Gen2      | Allocated  |
|------------ |--------:|---------:|---------:|------------:|-----------:|----------:|-----------:|
| LintProject | 3.916 s | 0.1088 s | 0.3088 s | 167000.0000 | 22000.0000 | 1000.0000 | 1007.31 MB |

But the change is also small so maybe it's still useful.

@Numpsy Numpsy marked this pull request as ready for review November 1, 2025 10:29
@Numpsy Numpsy force-pushed the create branch 2 times, most recently from 564d030 to 2cc0ea2 Compare November 11, 2025 09:36
@knocte
Copy link
Collaborator

knocte commented Nov 17, 2025

Not a fan of the <- operator TBH, maybe we can get similar gains by just using StringBuilder?

@Numpsy
Copy link
Contributor Author

Numpsy commented Nov 18, 2025

String.Create is supposed to allocate less than StringBuilder, but I haven't tried testing that here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants