question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggressive optimization and inlining foor PooledList.Span

See original GitHub issue

Is your feature request related to a problem? Please describe. Next method is kind of slow in Unity runtime (not sure about Core):

public Span<T> Span => _items.AsSpan(0, _size);

Describe the solution you’d like Mark this method as aggressive optimization and inlining.

Describe alternatives you’ve considered Provide unsafe access to writable array as ReadOnlyProperty.

Additional context We get data from Span by ref.

I know Core 3 optimized Span, but there are issues to measure that because of BDN-JIT instability. Same time Unity is involved into .NET Ecosystem and hopefully will optimize Span in some time (because people will use .NET Standard with Spans and Unity stated it is 2.0 and will be 2.1)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jtmuellercommented, Nov 28, 2019

Sorry for the delayed response. Here’s what I’m currently seeing without your suggested optimization, run from the “core3” branch:

Method Runtime N Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
PooledSpan .NET 4.8 1000 16.09 us 0.066 us 0.062 us - - - -
PooledIndex .NET 4.8 1000 17.42 us 0.093 us 0.087 us - - - -
PooledSpan .NET Core 3.0 1000 11.34 us 0.108 us 0.101 us - - - -
PooledIndex .NET Core 3.0 1000 17.44 us 0.107 us 0.100 us - - - -
PooledSpan .NET 4.8 10000 16.08 us 0.120 us 0.112 us - - - -
PooledIndex .NET 4.8 10000 17.43 us 0.074 us 0.069 us - - - -
PooledSpan .NET Core 3.0 10000 11.25 us 0.044 us 0.039 us - - - -
PooledIndex .NET Core 3.0 10000 17.38 us 0.108 us 0.101 us - - - -
PooledSpan .NET 4.8 100000 16.03 us 0.066 us 0.062 us - - - -
PooledIndex .NET 4.8 100000 17.41 us 0.110 us 0.103 us - - - -
PooledSpan .NET Core 3.0 100000 11.23 us 0.046 us 0.043 us - - - -
PooledIndex .NET Core 3.0 100000 17.47 us 0.088 us 0.082 us - - - -

And here’s what I’m seeing with AggressiveInlining applied to the “Span” property getter. There doesn’t seem to be a significant change by doing this. Perhaps I’m misunderstanding what you’re proposing?

Method Runtime N Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
PooledSpan .NET 4.8 1000 16.28 us 0.327 us 0.480 us - - - -
PooledIndex .NET 4.8 1000 17.41 us 0.138 us 0.130 us - - - -
PooledSpan .NET Core 3.0 1000 11.26 us 0.067 us 0.059 us - - - -
PooledIndex .NET Core 3.0 1000 17.35 us 0.090 us 0.084 us - - - -
PooledSpan .NET 4.8 10000 16.15 us 0.182 us 0.152 us - - - -
PooledIndex .NET 4.8 10000 17.41 us 0.164 us 0.145 us - - - -
PooledSpan .NET Core 3.0 10000 11.25 us 0.075 us 0.070 us - - - -
PooledIndex .NET Core 3.0 10000 17.38 us 0.111 us 0.104 us - - - -
PooledSpan .NET 4.8 100000 16.13 us 0.074 us 0.062 us - - - -
PooledIndex .NET 4.8 100000 17.37 us 0.111 us 0.103 us - - - -
PooledSpan .NET Core 3.0 100000 11.27 us 0.074 us 0.066 us - - - -
PooledIndex .NET Core 3.0 100000 17.38 us 0.079 us 0.070 us - - - -
public Span<T> Span
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    get
    {
        return _items.AsSpan(0, _size);
    }
}
0reactions
dzmitry-lahodacommented, Nov 29, 2019

MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization ? It may not help either. But at least, in Unity IL2CPP both span and index were slow, so people put items array as public. So if nothing changes, may be leave both optimization in place so that possible other runtimes will have more chances to hit the optimization? Just as idea, but anyway - may close the issue. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a downside to using AggressiveInlining on simple ...
Inlining is one of them, whether the programmer wanted or not. For example, MethodImplOptions does not have an "inline" option. Because inlining ......
Read more >
c# - Specifically what does a compiler do to aggressively ...
Strip all symbols from a module; Strip debug info for unused symbols ... Here are two simple optimizations a compiler could make:
Read more >
Inlining and Compiler Optimizations
More interestingly, though, inlining enables other compiler optimizations. In this article, I will show examples of constant propagation and ...
Read more >
3.11 Options That Control Optimization
Consider all functions for inlining, even if they are not declared inline. The compiler heuristically decides which functions are worth integrating in this...
Read more >
Methods to Optimize Code Size
The browser version you are using is not recommended for this site. Please consider upgrading to the latest version of your browser by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found