This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
Conversation
| [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] | ||
| public extern int GetUpperBound(int dimension); | ||
|
|
||
| private int _lowerBound0 = 0; |
There was a problem hiding this comment.
Huh? An new field added to the Array class?
Author
There was a problem hiding this comment.
Yes, this is how we short circuit GetLowerBound(0). Is this a problem
There was a problem hiding this comment.
Yep, it's a problem. Fields cannot be added to the Array class as its layout (or to be precise, the layout of types derived from Array) is determined by the runtime. And even if it was possible you certainly don't want to increase the size of array objects by adding a field.
Author
There was a problem hiding this comment.
Well shucks I had no idea! Ah well eh, closing this up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Array.GetLowerBounds(0) is an extremely common operation on an Array: it is called pretty much everytime you call an Array method (Copy, Contains, IndexOf, BinarySearch, GetEnumerator, LastIndexOf, Reverse, Sort)
Currently, the implentation of GetLowerBound calls native code and validates parameters etc.
It can be found here
Instead, we can check immediately for the LowerBound of an array for dimension 0.
Currently, this PR is a slight WIP, as I don't know how to conduct perf tests for a locally built mscorlib. If someone could help me with this I'd really appreciate that. I expect perf to improve for
GetLowerBound(0)but to worsen very slightly forGetLowerBound(dimension)wheredimension > 0as we have one additional branch and method invoke.I think arrays are only created with custom lower bounds via
CreateInstance(Type, int[], int[])but let me know if I'm wrong here, and I will update the code to set_lowerBound0where necessary./cc @jkotas @jamesqo