Twitter | Search | |
Sergio Pedri
UWP and .NET developer, creator of Legere and OneLocker. member. Computer Engineering student. Occasionally blog at .
1,842
Tweets
98
Following
491
Followers
Tweets
Sergio Pedri 23h
Replying to @ckindel
The hat operator indicates an index from the end though, if you want the Substring(0, n) equivalent shouldn't you be using line[0..n] instead? Also, if the initial index is 0 you can just omit it for brevity and just write line[..n], same output πŸ™‚ Repro:
Reply Retweet Like
Sergio Pedri Mar 29
Replying to @SergioPedri
Here's the link to the blog post for those who have missed it, super interesting and a highly recommended read: . Egor definitely knows his way around both LLVM and RyuJit πŸ‘
Reply Retweet Like
Sergio Pedri Mar 29
Brainstorming some ideas, and I came up with some improvements to LLVM's optimization of range checks that explained in his blog post. In particular, not using char to skip a movzx, and an unsafe cast to avoid the second branch. Would this be useful?
Reply Retweet Like
Sergio Pedri Mar 27
Would the new Memory<T>-based Stream type in the HighPerformance toolkit package help? You can get a Memory<T> over your array to select the range you need, then get a stream from it. There are also other helper types that work with array pooling. Full PR:
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @firstdrafthell
Glad I could help! And yeah I hear you, this is one of the things that has always bugged me the most about the BCL as well πŸ˜†
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @firstdrafthell
I think it doesn't for the same reason why ICollection<T> and IReadOnlyCollection<T> aren't in the same inheritance tree (same for eg. IList<T> and IReadOnlyList<T>): backwards compatibility. See and . It's really be nice if it did!
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
That can be done through MemoryMarshal.CreateSpan(ref T, int), at least. Which is also one of the points of this lib: exposing features that are "more or less" possible, but tricky to achieve from scratch for many developers. A .NET 5 GetReference for ND arrays would be nice!
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
Yup, I saw that! I think I'll definitely propose some helper APIs for 2D arrays, though from what I've seen it's pretty difficult to get APIs approved into CoreCLR (for good reason, sure). It'd be very nice to eg. at least have a built-in way to create a Span<T> from a 2D array.
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
Then when there is a new major release that can introduce breaking changes, after .NET 5 is available, we could remove those frameworks and only leave .NET Standard 2.0/2.1 and .NET 5, and base all these tricks on the official CoreCLR specs to be extra safe. Does this sound ok?
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
Ah, yeah that makes a lot of sense, thanks! I think the best course of action at this point could be to consider adding the netcoreapp2.1/3.1 and uap10.0.16299 targets as well, and restrict these runtime-dependent APIs on those frameworks only. That should make everyone happy 😊
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
Shouldn't that be safe though as long as you're just comparing the references and not actually dereferencing them? As far as I know, AVEs and other issues only appear when trying to access locations, whereas just storing managed refs to arbitrary locations is fine, right?
Reply Retweet Like
Sergio Pedri Mar 26
Replying to @MStrehovsky
Thank you for the additional info Michal! I figured there might be some issues with Mono at the moment, so I thought it'd be a good idea to also add a couple of properties like this to validate these APIs. On that point, I'm so glad everything's coming together with .NET 5! πŸ₯³
Reply Retweet Like
Sergio Pedri Mar 25
Replying to @James_M_South
Good... Good... Let the Unsafe flow through you...
Reply Retweet Like
Sergio Pedri Mar 25
Replying to @SergioPedri
The trick is similar to the one used to access data from SZ arrays, just with the additional fields to account for the different layout. I'm also using this mapping type to access the width field directly, to avoid the GetLength(1) call and save time. New extensions coming! πŸŽ‰
Reply Retweet Like
Sergio Pedri Mar 25
"Accessing 2D arrays in C# is always very slow" Hold my :
Reply Retweet Like
Sergio Pedri Mar 19
Replying to @fonssonnemans
I have not so far, but I put together a small gist for you with the code I wrote to run this benchmark (just removed my app-specific code). It's not as advanced as BenchmarkDotNet, but it's a good starting point and it works on UWP as well, hope it helps!
Reply Retweet Like
Sergio Pedri Mar 19
Replying to @MStrehovsky @ufcpp
Hey Michal! πŸ‘‹πŸ» The Unsafe class is indeed available everywhere (using it in this .NET Standard package too), but are you sure about Unsafe.Unbox? The docs say it's only available from .NET Core 3.0, and I can't seem to find it in the .NET Standard project:
Reply Retweet Like
Sergio Pedri Mar 18
Replying to @antonfrv
That's pretty similar, barely more efficient just because I'm not loading arguments to pass to the throw exception method. The main advantage of this type is the faster speed when you're sure, the ref T getter, and the fact that using Box<T> is more explicit than just object.
Reply Retweet Like
Sergio Pedri Mar 18
This type only relies on .NET Standard 2.0 APIs, which are supported by Unity, so yeah it should definitely be possible to use Box<T> (as well as the entire HighPerformance package, once it's released) on Unity as well πŸ‘
Reply Retweet Like
Sergio Pedri Mar 18
Replying to @antonfrv
Yes, Twitter, having a gigantic and badly cropped version of my avatar is exactly what I wanted, thank you very much πŸ˜†
Reply Retweet Like