Skip to content

Conversation

TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Mar 6, 2025

Taking inspiration from Roslyn I added several implementation of Concat one for each number of children and WithManyChildren.
This lets us use Concat(params ReadOnlySpan<Doc> values, this way we can use WithTwoChildren or WithThreeChildren when there is a small numbers of values, only allocating to an array when there is a large number of Doc types.

This currently saves 2 MB (6% memory usage) however I expect this number to go up when combined with #1502

belav added a commit that referenced this pull request Apr 4, 2025
Follow on from #1502, using `ValueListBuilder` to replace known
`List<Doc>` sizes.

- Most of these changes aren't measurable in the benchmarks, many are
insignificant, although I suspect this is partly due to the limited code
found in the benchmark file.
- This PR will increase the performance benefits of #1524



@belav what do you think the best way of replacing a list that uses a
collection initializer is?

I can either add the items directly into the scratch buffer and manually
update `Length`
```C#
var docs = new ValueListBuilder<Doc>
([
    Modifiers.Print(node.Modifiers, context),
    Token.Print(node.DelegateKeyword, context),
    null,null
]);
docs.Length = 2;
```

Or create the buffer and then append the items via params.
```C#
var docs = new ValueListBuilder<Doc>([null, null, null, null]);
docs.Append(
    Modifiers.Print(node.Modifiers, context),
    Token.Print(node.DelegateKeyword, context)
);
```
Or Append each item
```C#
var docs = new ValueListBuilder<Doc>([null, null, null, null]);
docs.Append(Modifiers.Print(node.Modifiers, context));
docs.Append(Token.Print(node.DelegateKeyword, context));
```

---------

Co-authored-by: Bela VanderVoort <[email protected]>
@belav belav force-pushed the main branch 4 times, most recently from eeaf247 to 9e9ad83 Compare July 10, 2025 15:48
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.

1 participant