Skip to content

[Blazor WASM] - Investigate 8% size regression in System.Memory.dll.br #51571

Description

@SamMonoRT

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Apr 20, 2021
  2. GrabYourPitchforks commented on Apr 20, 2021

    @GrabYourPitchforks
    Member

    @SamMonoRT Do you have the raw files on disk for the before and after images? That would definitely help investigation, since we could look at the entire call graph and see if the regression was due to code within System.Memory or is due to changes in one of its callers.

  3. SamMonoRT commented on Apr 20, 2021

    @SamMonoRT
    MemberAuthor

    I don't have that information. I just saw an auto-filled issue by @DrewScoggins which has some more information : DrewScoggins/performance-2#5087

  4. DrewScoggins commented on Apr 20, 2021

    @DrewScoggins
    Member

    Do you need the trimmed files or the actual full binaries from the NETCore.App package?

  5. DrewScoggins commented on Apr 20, 2021

    @DrewScoggins
    Member

    I will also copy over the full contents of the auto-filed issues, as it contains a few other dlls that have small regressions as well.

    Run Information

    Architecture x64
    OS ubuntu 18.04
    Baseline 7fa839a727e510f2b1b104eafb2c1fb339249756.
    Compare ee0719079c4c4540f5adb135f002ad3ecf6c25ea
    Diff Diff

    Regressions in SOD - New Blazor Template - Publish

    Benchmark Baseline Test Test/Base Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Collections.dll 22.00 KB 23.50 KB 1.07
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Text.Json.dll.br 79.08 KB 83.19 KB 1.05
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Memory.dll 17.50 KB 19.00 KB 1.09
    SOD - New Blazor Template - Publish - Aggregate - .dll 2.09 MB 2.12 MB 1.01
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Text.Json.dll 240.50 KB 253.00 KB 1.05
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Collections.Concurrent.dll 17.00 KB 17.50 KB 1.03
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Collections.dll.gz 9.79 KB 10.45 KB 1.07
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.ObjectModel.dll.br 2.74 KB 2.77 KB 1.01
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Memory.dll.gz 8.59 KB 9.26 KB 1.08
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Text.Json.dll.gz 92.47 KB 97.24 KB 1.05
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Memory.dll.br 7.72 KB 8.26 KB 1.07
    SOD - New Blazor Template - Publish - pub/wwwroot/_framework/System.Collections.dll.br 8.82 KB 9.38 KB 1.06

    graph
    graph
    graph
    graph
    graph
    graph
    graph
    graph
    graph
    graph
    graph
    graph
    Historical Data in Reporting System

    Repro

    git clone https://github.com/dotnet/performance.git
    python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'SOD - New Blazor Template - Publish*'
    Details

    Histogram

    SOD - New Blazor Template - Publish

    
    

    Docs

    Profiling workflow for dotnet/runtime repository
    Benchmarking workflow for dotnet/runtime repository

  6. GrabYourPitchforks commented on Apr 20, 2021

    @GrabYourPitchforks
    Member

    The files after trimming but before compression would be best. That way I can plug the whole mess through ilspy and see what changed.

  7. DrewScoggins commented on Apr 20, 2021

    @DrewScoggins
    Member
  8. DrewScoggins commented on Apr 20, 2021

    @DrewScoggins
    Member

    I am also going to make a change so that these artifacts are preserved by Helix, as reproducing them took me about 30 minutes.

  9. GrabYourPitchforks commented on Apr 20, 2021

    @GrabYourPitchforks
    Member

    Sorry, I should clarify: I need all files, not just System.Memory.dll. Otherwise I can't go back in the call graph.

  10. DrewScoggins commented on Apr 20, 2021

    @DrewScoggins
    Member

    Oh, sorry about that. Here is what you need.

    Baseline
    Compare

  11. GrabYourPitchforks commented on Apr 21, 2021

    @GrabYourPitchforks
    Member

    The trimmed compare file graph contains lots of code to support ArrayBufferWriter<T> - this code wasn't in the trimmed baseline graph. I'm still trying to track down who is calling this.

    image

  12. GrabYourPitchforks commented on Apr 21, 2021

    @GrabYourPitchforks
    Member

    My best guess is that this is a consequence of #51025. The JSON stack now has direct dependencies to JsonNode which can't be trimmed away, and JsonNode itself has direct dependencies to ArrayBufferWriter<T> which can't be trimmed away.

    var output = new ArrayBufferWriter<byte>();
    using (var writer = new Utf8JsonWriter(output, options))
    {
    WriteTo(writer);
    }
    return JsonHelpers.Utf8GetString(output.WrittenSpan);

    Specifically, the above code instantiates an ArrayBufferWriter<T> and passes it around, which means the linker needs to keep all the method implementations around. Previously, even though ArrayBufferWriter<T> still existed as a type (because the JSON stack had a field reference to it), the linker had been nuking all of the method implementations.

    // System.Buffers.ArrayBufferWriter<T> - BASELINE
    using System;
    using System.Buffers;
    using System.Runtime.CompilerServices;
    
    public sealed class ArrayBufferWriter<T> : IBufferWriter<T>
    {
    	public ReadOnlyMemory<T> WrittenMemory
    	{
    		[MethodImpl(MethodImplOptions.NoInlining)]
    		get
    		{
    			throw new NotSupportedException("Linked away");
    		}
    	}
    
    	public ReadOnlySpan<T> WrittenSpan
    	{
    		[MethodImpl(MethodImplOptions.NoInlining)]
    		get
    		{
    			throw new NotSupportedException("Linked away");
    		}
    	}
    
    	public int WrittenCount
    	{
    		[MethodImpl(MethodImplOptions.NoInlining)]
    		get
    		{
    			throw new NotSupportedException("Linked away");
    		}
    	}
    
    	[MethodImpl(MethodImplOptions.NoInlining)]
    	public void Clear()
    	{
    		throw new NotSupportedException("Linked away");
    	}
    
    	[MethodImpl(MethodImplOptions.NoInlining)]
    	public void Advance(int count)
    	{
    		throw new NotSupportedException("Linked away");
    	}
    
    	[MethodImpl(MethodImplOptions.NoInlining)]
    	public Memory<T> GetMemory(int sizeHint = 0)
    	{
    		throw new NotSupportedException("Linked away");
    	}
    }
  13. layomia commented on Apr 21, 2021

    @layomia
    Contributor

    Related to #51311.

    The JSON stack now has direct dependencies to JsonNode which can't be trimmed away

    FWIW the node types can't be trimmed away today because it is rooted by these converters which are in turn rooted by this logic, which happens when existing JsonSerializerOptions-based methods of JsonSerializer are used. When Blazor is updated to use new metadata-based APIs on JsonSerializer (dotnet/aspnetcore#31877), I expect that these converters will be trimmed out if not needed by the application.


    cc @steveharter on thoughts on whether we can minimize the dependency on ArrayBufferWriter<T> for apps that use the node feature.

  14. added this to the 6.0.0 milestone on Apr 21, 2021
  15. removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 21, 2021
  16. steveharter commented on Apr 21, 2021

    @steveharter
    Contributor

    We can change the implementation to use PooledByteBufferWriter instead. That is what the non-Stream paths use today (the Stream paths use ArrayBufferWriter<T>.

  17. self-assigned this
    on Apr 21, 2021
  18. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 26, 2021
  19. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 27, 2021
  20. SamMonoRT commented on Apr 28, 2021

    @SamMonoRT
    MemberAuthor

    Thanks for the quick change, resulted in decrease in size :

    image

  21. ghost locked as resolved and limited conversation to collaborators on May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions