-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Uri] A lightweight alternative for System.Uri #34873
Comments
Tagging @dotnet/ncl as an area owner. If you would like to be tagged for a label, please notify danmosemsft. |
It tries not to - it will lazily parse more if/when some properties are actually read. One big problem with this rn is that if the Uri contains just a single non-ascii char/escaped sequence it will give up completely and do a full parse every time. Changing this would be beneficial, though not trivial. Before considering a new type, we should invest into perf improvement opportunities in the Uri implementation. Work that improves Uri for net5 like #34864 #32552 #34774 #34794 #32025 #32694 #31860 will improve throughput and allocations (especially if you deal with Uris containing any non-ascii chars). More considerations such as #34618 should remove all overhead in cases when making multiple requests to the same REST API path. This should be very common given how many APIs are using POST, where the Uri can be reused. #32606 and #32606 (comment) for improving perf when working with query strings. UriBuilder is another type that can be significantly improved, and there are more improvements that could be made in Uri itself. It's possible we could expose an API to fetch properties into a Span (suggested in #22903 (comment)) to avoid some overhead. It is now feasible to implement such an API, after changes like #34864. That said, I wouldn't mind a high-perf type that only deals with Uris relevant to
Are you dealing with Uris that contain non-ascii chars? If you've measured perf here, are you seeing a lot of CPU spent or just a ton of allocations? If it's a lot of CPU time you are seeing, could you share a sample Uri that you are dealing with. |
I don't have examples of the most expensive uris, but i think i have an snapshot of a trace from our Api Gateway (runs on dotnetcore), it sees all uris from all microservices. This is the use breakdown from that app, in this case is net5 preview2 on windows. I'll try to check if non-ascii chars is a common case. |
@Rodrigo-Andrade how much CPU % does the whole |
How are the Uris being used - only getting passed to HttpClient, or are you accessing other properties? Yes, quite a lot of Uri improvements went into the 5.0 release. |
Only getting passed to HttpClient. |
Just an update, the new ctor: |
Have you tried benchmarking your scenario on 6.0 without using the new ctor? There were significant improvements to There is some more context behind the API in #59099. The key reasons behind it being #52628 and #58057. |
I wonder if we can close the issue then. Looks like the major concern has been addressed. |
I think you may, but this will eventually come back i think. |
Sure, if it comes back with reasonable scenarios and impact on customers/apps, we can always revisit. Perhaps our iterations on perf will eventually show it up in traces and that might make the case. |
@Rodrigo-Andrade if you are seeing a performance improvement from using |
As the
SocketsHttpHandler
gets faster, many of my hot paths are now inSystem.Uri class.
There is a lot of parsing in any case of paths and/or QueryString parameters that varies on each request.
System.Uri
will always validate the entire string, not to mention that a string must be allocated each time. Would be nice to have an alternative, be forsakeSystem.Uri
for a new type inHttpRequestMessage
, or provide "unsafe" apis forSystem.Uri
, so it would not validate every part.The text was updated successfully, but these errors were encountered: