Search Issue Tracker

By Design

Votes

2

Found in

2018.3.0b8

2018.3.0f2

2019.1.0a1

2019.2.0a1

Issue ID

1123117

Regression

No

[.NET 4.x] "StringBuilder" generates more garbage in .NET 4.x than in .NET 3.5

Mono

-

Reproduction steps:

1. Open "StringBuilderGC.zip" project
2. Open Profiler window and enable "Deep Profile"
3. Enter Play mode
4. At the first frame search for "Test.Start()"
5. Notice the "GC Alloc" is '4.6 KB' and '2.2 KB'
6. Repeat steps 2-5 with .NET 3.5
7. Notice the "GC Alloc" is '3.6 KB' and '1.1 KB'

Expected Result: .NET 4.x generates less Garbage than .NET 3.5
Actual Result: .NET 4.x generates twice the amount of Garbage compared to .NET 3.5

Reproduced with: 2019.2.0a4, 2019.1.0b2, 2018.3.5f1
Did not reproduce on: 2017.4.20f1

  1. Resolution Note:

    The class library implementation for StringBuilder was changed upstream from mono's own implementation to microsoft's referencesource implementation. This means that the profile of allocations between 3.5's and 4.x's will be different.

Comments (1)

  1. Gladyon

    Feb 17, 2019 17:53

    I understand that it is coming from the Microsoft implementation of 'StringBuilder' which is used now (before it was Mono's implementation).

    So I agree that it is 'by design', but does it have to stay like that?
    It is possible to implement StringBuilder in another way, in order to reduce GC.

    After all, Microsoft has designed StringBuilder mostly for 'standard' software, not for games, so it's understandable that they do not have optimized the StringBuilder implementation in order to reduce GC.
    But Unity3D is mainly used to create games, and in games reducing GC is very important, so I really think that Unity should have its own implementation of StringBuilder in order to optimize it as it should be for games.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.