Comments (5)
Did not help on indexer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
But Throw helped!!!!
Method | Mean | Error | StdDev | Ratio | RatioSD |
------------------------ |-----------:|---------:|----------:|------:|--------:|
ListIndexer_Int | 1,875.4 ns | 37.47 ns | 94.00 ns | 1.00 | 0.00 |
PooledIndexer_Int | 1,869.6 ns | 37.35 ns | 71.95 ns | 0.99 | 0.07 |
PooledIndexer_items_Int | 528.0 ns | 12.86 ns | 37.91 ns | 0.28 | 0.03 |
ListIndexer_String | 3,756.4 ns | 73.98 ns | 160.83 ns | 2.00 | 0.12 |
PooledIndexer_String | 3,803.3 ns | 91.27 ns | 269.11 ns | 2.02 | 0.17 |
public T this[int index]
{
get
{
// Following trick can reduce the range check by one
if ((uint)index >= (uint)_size)
{
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
}
return _items[index];
}
internal static void ThrowArgumentOutOfRange_IndexException()
{
throw new ArgumentOutOfRangeException("index");
}
from collections.pooled.
I've checked in updates that add ThrowHelper back to both PooledList and PooledDictionary, and in every benchmark I've run so far this has fixed the performance regressions. I've yet to see a case where the pooled collection fails to have as-good-or-better performance. Thanks again for figuring out what I was overlooking!
I haven't published an updated NuGet package yet. I want to re-run all the benchmarks on both platforms and check for any nasty surprises first, and I probably won't be done with that until sometime tomorrow in my time zone.
from collections.pooled.
Seems I found https://github.com/dotnet/corefx/blob/21e5d0f2f42110ae4500577588948d48346ff322/src/Common/src/CoreLib/System/ThrowHelper.cs .
Would you be able to fix that? I.e. use ThrowHelper in indexer rather than exception?
I guess there are other places to fix, not only one. So may be work on issues as whole?
from collections.pooled.
Making _items
makes runs as fast as span. I am running with index inlining and will run with throw than.
from collections.pooled.
Wow, nice catch! I took all the ThrowHelper calls out because it was one less thing to port over and I didn't realize there were performance implications. (To be frank, I assumed the ThrowHelper stuff had more to do with localization of error messages than performance, and I didn't want to port an internal localization system over on top of everything else.) I would have thought that an exception I wasn't even throwing because the index was valid could not affect performance like that. I've learned something new!
I'll definitely be pulling a copy of ThrowHelper into Collections.Pooled and restoring the calls to it. Then I'll re-run all the benchmarks.
from collections.pooled.
Related Issues (20)
- PooledList.Dispose semantics HOT 6
- Support for .NET Standard 2.1 HOT 15
- Disposing PooledDictionary doesn't dispose PooledList stored as values HOT 2
- Support for ObservableCollection HOT 6
- GC of boxing if key is struct HOT 1
- Aggressive optimization and inlining foor PooledList.Span HOT 5
- Retrieve Memory<T> from PooledList<T>
- Nested pooled collections crash the Visual Studio heap snapshot
- Resurrect rented buffers or arrays in finalyzer HOT 1
- Pooled Lookup
- Pooled Array
- PooledSet is generating GC when item gets removed HOT 1
- Add equivalent of CollectionsMarshal.GetValueRef for PooledDictionary.
- Why not implents INotifyCollectionChanged or provide a BindingVersion
- linq benefits from pooled? HOT 1
- Consider PooledSortedList
- Is the repos alive?
- How about call GC.SuppressFinalize(this) to prevent add to finalization queue.
- PooledDictionary.Remove with Count 0 = Exception HOT 1
- Upgrad and support .net 6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collections.pooled.