Skip to content

Conversation

@huoyaoyuan
Copy link
Member

Extracted from #109114.

In coreclr implementation, PEAssembly::GetResource also does a linear search for the resource. A typical caller would also cache the returned resource.

The resultant complexity would be O(assembly+resource) not O(assembly*resource), so there's not much concern about time regression.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 10, 2025
@huoyaoyuan huoyaoyuan added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 10, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Jul 2, 2025

there's not much concern about time regression.

Could you please collect some perf numbers so that we understand how much we are giving up here?

@huoyaoyuan
Copy link
Member Author

Could you please collect some perf numbers so that we understand how much we are giving up here?

Testing a single assembly with 1000*10KB resources:

        [Benchmark]
        public string[] GetResourceNames() => typeof(Program).Assembly.GetManifestResourceNames();

        [Benchmark]
        public Stream GetResource567() => typeof(Program).Assembly.GetManifestResourceStream("BenchmarkGround.res.567.bin");

Main:

Method Mean Error StdDev
GetResourceNames 1.835 us 0.0139 us 0.0123 us
GetResource567 2.408 us 0.0468 us 0.0539 us

PR:

Method Mean Error StdDev
GetResourceNames 1.754 us 0.0351 us 0.0311 us
GetResource567 2.342 us 0.0293 us 0.0274 us

It even looks an improvement?

@jkotas
Copy link
Member

jkotas commented Jul 2, 2025

Testing a single assembly with 1000*10KB resources:

Assembly with 1000 resources is not very typical case. A typical case is <10 resources.

@huoyaoyuan
Copy link
Member Author

For assembly with 20 resource:

main:

Method Mean Error StdDev
GetResourceNames 533.7 ns 2.59 ns 2.42 ns
GetResource10 491.3 ns 3.14 ns 2.79 ns
GetResource20 535.0 ns 2.15 ns 2.01 ns

PR:

Method Mean Error StdDev
GetResourceNames 541.3 ns 4.02 ns 3.76 ns
GetResource10 496.3 ns 3.66 ns 3.43 ns
GetResource20 544.6 ns 3.48 ns 3.08 ns

It looks a very little regression, but not much for typical usages.

@jkotas
Copy link
Member

jkotas commented Jul 3, 2025

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@jkotas jkotas enabled auto-merge (squash) July 4, 2025 05:18
@jkotas jkotas merged commit 4cc3020 into dotnet:main Jul 4, 2025
92 of 97 checks passed
@huoyaoyuan huoyaoyuan deleted the manifest-resource branch July 4, 2025 07:33
@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants