Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Optimizaiton of DefaultModelBinderLocator #2361

Conversation

thecodejunkie
Copy link
Member

Minor tweak while chasing bigger dragons. The DefaultModelBinderLocator figured out which model binder is should use for a specific model type. This is part of a 100k requests sample where model binding is involved

  • Removed use of LINQ in the resolving

Before
image

After
image

@thecodejunkie thecodejunkie added this to the 2.0 milestone Mar 15, 2016
@thecodejunkie thecodejunkie force-pushed the benchmark-defaultmodelbinderlocator branch from 42d0a09 to 90d8e3e Compare March 15, 2016 11:49

if (binders != null)
{
this.binders = binders.ToArray();
Copy link
Member

Choose a reason for hiding this comment

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

This is the same as my comment on the other issue, but I believe you can do:

this.binders = new ReadOnlyCollection(binders);

This means it will work on the original collection and not copy it to a new one.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't wrap it because it's IEnumerable<T> which means we need to materialize the collection first using either ToList or ToArray.

Copy link
Member

Choose a reason for hiding this comment

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

As discussed in chat, can't cast the value :(

phillip-haydon added a commit that referenced this pull request Mar 16, 2016
…derlocator

Optimizaiton of DefaultModelBinderLocator
@phillip-haydon phillip-haydon merged commit c6008c6 into NancyFx:master Mar 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants