Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Configuration binder performance #604

Closed

Description

@passuied

It seems that the current implementation of the ConfigurationBinder is relying heavily on reflection which would have significant performance impact when binding a type multiple times over.

I know the current options pattern leveraging this binding is using Singletons and only rebinds on reload but in our application we are tweaking the options behavior so it can be resolved per lifetime scope instead which would cause all our options classes to be rebound for every request.

Would leveraging expression trees help in this case to limit the reflection on a given options type?

Thoughts?

Activity

  1. davidfowl commented on Feb 24, 2017

    @davidfowl
    Member

    As a standalone component that can be used over and over I think it would be a fine contribution to have a method that creates a typed binder. It wouldn't be something we'd use by default since as you said, we do this mostly on singletons.

    but in our application we are tweaking the options behavior so it can be resolved per lifetime scope instead which would cause all our options classes to be rebound for every request.

    How are you "tweaking" the options behavior? You can't change the lifetime of the existing IOptions<T> that would potentially break too much stuff.

  2. divega commented on Feb 24, 2017

    @divega

    There are lifetime changes happening in 2.0 due to IOptionsSnapshot<T> and enabling scoped IConfiguredOptions<T> so in principle this is relevant. It would be good to have some measurements of the perf.

    Cc @HaoK

  3. passuied commented on Feb 24, 2017

    @passuied
    Author

    @davidfowl,

    How are you "tweaking" the options behavior? You can't change the lifetime of the existing IOptions that would potentially break too much stuff.

    I'm using IOptionsSnapshot which is registered per Lifetimescope, since it needs to reload on change. However it has currently a dependency on IOptionsMonitor which is still registered as a singleton.
    I am planning to test today to change the registration of this latter to a Lifetime scope also which I hope would give me the correct behavior.
    However, the main down side I see is that it will now bind the options for every request, which is where Performance during Configuration binding will be a big deal.

    @divega, if my change above works, I'm planning to make some measurements of the perf but I'm assuming the current implementation is not great, and implementing a TypeBinder would help greatly for repeated binding of the same type.

    As a side note, the reason why I need to rebind on every request is for multi-tenancy purposes. See my comments in issue: #584

    Cc @HaoK

  4. HaoK commented on Feb 24, 2017

    @HaoK
    Member

    Yup that was actually a bug and we fixed that in 2.0, where the snapshot is basically just a scoped equivalent of IOptions/OptionsManager, see aspnet/Options#164

    I'll take a look at the binder performance

  5. ajcvickers commented on Apr 25, 2017

    @ajcvickers
    Contributor

    Considering for 2.0 for now, since binder may be used more. May punt if perf looks okay in common scenarios.

  6. added this to the 2.0.0 milestone on Apr 25, 2017
  7. davidfowl commented on Apr 26, 2017

    @davidfowl
    Member

    We should start by adding micro benchmarks.

  8. modified the milestones: Backlog, 2.0.0 on May 16, 2017
  9. removed their assignment
    on Aug 30, 2018
  10. removed this from the Backlog milestone on Dec 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions