Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change JumpTable to take ReadOnlySpan #22397

Closed
wants to merge 2 commits into from
Closed

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented May 31, 2020

  • Small change while trying to get a better handle on the part of the code base. Today we pass a string and 2 pointers and instead we can pass a ReadOnlySpan<char>.
  • Updates tests and IL generator to handle the new signature.

TODO: Run perf tests

@ghost ghost added the area-servers label May 31, 2020
@@ -663,37 +663,6 @@ internal Candidate CreateCandidate(Endpoint endpoint, int score)
}
}

private int[] GetGroupLengths(DfaNode node)
Copy link
Member Author

Choose a reason for hiding this comment

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

Unused

{
return _exitDestination;
}

var text = path.Substring(segment.Start, segment.Length);
var text = path.ToString();
Copy link
Member Author

Choose a reason for hiding this comment

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

@GrabYourPitchforks @stephentoub @jkotas it would be great to allow lookup by ReadOnlySpan<char> without the added allocation (closest issue I saw was this dotnet/runtime#27229)

Copy link
Member

Choose a reason for hiding this comment

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

Yes. The sticking point has been with a design regarding custom comparers:
dotnet/runtime#28368 (comment)

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks Jun 4, 2020

Choose a reason for hiding this comment

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

One other sticking point is that there's no guarantee that the same algorithm is used to compute the hash code of a string vs. the hash code of a ReadOnlySpan<char>. In fact, Dictionary<string, ...> throws away the default comparer and uses a specialized string comparer for greater performance. It's definitely solvable, but doing this in a manner that won't regress performance of existing scenarios is a much more complex problem than it appears.

Edit: The reason this matters is that the hash code is needed to compute which bucket the key maps to. If we inadvertently compute the wrong hash code, we could end up in a situation where the dictionary truly does contain some string value but we say it doesn't contain the equivalent ROS<char> value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I get it but how do we make progress? Does somebody just have to ask again? Do we have proposals?

Copy link
Member

@stephentoub stephentoub Jun 4, 2020

Choose a reason for hiding this comment

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

My proposal is what's in my linked comment: throw from the method if the comparer being used is not one we implicitly understand and can handle internally appropriately. It's not perfect, it's not beautiful, but it addresses what I think is the 99% case: using one of the built-in comparers. The downside is there's a big cliff that manifests as either an exception or string allocation when the comparer isn't supported. If we went with exception, we could make it work in the future if we added another interface supporting spans we could query for.

Copy link
Member

Choose a reason for hiding this comment

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

There are a few candidate proposals in dotnet/runtime#27229. (But Steve, I don't see your idea reflected there? Maybe I'm looking at the wrong piece?) The issue is currently marked as needs work and has no assignee. Somebody would need to champion it and drive it through API review.

Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

I'm interested to see the impact on benchmarks. We benchmarked the heck out of this area so there are many micro benchmarks

@davidfowl
Copy link
Member Author

I'm interested to see the impact on benchmarks. We benchmarked the heck out of this area so there are many micro benchmarks

Yea me too, I can't get it running..

@davidfowl
Copy link
Member Author

davidfowl commented Jun 6, 2020

OK the microbenchmarks are broken in master 😞

@davidfowl davidfowl closed this Jun 11, 2020
@davidfowl davidfowl reopened this Jun 11, 2020
- Small change while trying to get a better handle on the part of the code base. Today we pass a string and 2 pointers and instead we can pass a ReadOnlySpan.
- Updates tests and IL generator to handle the new signature.
@davidfowl davidfowl closed this Jul 14, 2020
@dougbu dougbu deleted the davidfowl/span-routing branch August 21, 2021 22:35
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants