-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Remove some Linq usages from Kestrel.Core #47012
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,20 @@ public class KestrelServerOptions | |
// The following two lists configure the endpoints that Kestrel should listen to. If both lists are empty, the "urls" config setting (e.g. UseUrls) is used. | ||
internal List<ListenOptions> CodeBackedListenOptions { get; } = new List<ListenOptions>(); | ||
internal List<ListenOptions> ConfigurationBackedListenOptions { get; } = new List<ListenOptions>(); | ||
internal IEnumerable<ListenOptions> ListenOptions => CodeBackedListenOptions.Concat(ConfigurationBackedListenOptions); | ||
|
||
internal ListenOptions[] GetListenOptions() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it really be that bad to leave it as a property? It's not that expensive, and might be easier than tracking down all the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can leave it as a property, but I really dislike allocating in a property getter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: are the two lists mutated much at the moment? Thery could be stored in a single list or array, with an int that marks the split between the two chunks. Then the combined list is "ignore the split", and the other two lists are just separate pieces of the single chunk - ideally returning either RwadOnlyMemory-ListenOptions, ReadOnlySpan-ListenOptions, or ArraySegment-ListenOptions. If it is easiest to use a list when building, theres a CollectionsMarshal API to sneak inside when needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a quick investigation, for a The way The way They are kept separate in order to correctly "reload" on configuration changes. Kestrel knows which ones were added by the previous configuration, and can remove any endpoints that are now removed. I think your idea might be a good idea, but I think it is out of scope for this PR. Feel free to open a separate PR for it. |
||
{ | ||
int resultCount = CodeBackedListenOptions.Count + ConfigurationBackedListenOptions.Count; | ||
if (resultCount == 0) | ||
{ | ||
return Array.Empty<ListenOptions>(); | ||
} | ||
|
||
var result = new ListenOptions[resultCount]; | ||
CodeBackedListenOptions.CopyTo(result); | ||
ConfigurationBackedListenOptions.CopyTo(result, CodeBackedListenOptions.Count); | ||
return result; | ||
} | ||
|
||
// For testing and debugging. | ||
internal List<ListenOptions> OptionsInUse { get; } = new List<ListenOptions>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many do we expect? Almost none? Almost all? I'm thinking "list initial size" reasons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At most it is
_transports.Count
. At minimum, it is0
. I'm not sure what the typical case would be.This is only called on
RebindAsync
, which happens when the configuration changes and there are endpoints to stop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it. There are much bigger optimizations we could make to endpoint rebinding if we cared more about this scenario. For example, we could start bringing new endpoints online before completely stopping all the removed ones if they don't conflict.