-
Notifications
You must be signed in to change notification settings - Fork 140
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
Constrained routes take 2 #170
Conversation
…the generic name deriveConstraint
…ned handler retrieval
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.
lgtm
ping @delvedor care to take another look? |
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.
LGTM
Before merging this I would kindly ask you to remove the not necessary empty object you have added in some test when calling find
, given that it's not required we should not have it there, otherwise we risk to create a false positive test :)
Woo!
I think I might have been unclear about what that value is actually for because I consider that arg very much required. For the system to meet its contract, the caller needs to think about what is passed for that argument and pass something, it just might be that the value passed is undefined for performance reasons. Most direct callers of The reason is that within the realm of this library, I think constraints must be a thing that contributors care about. If they go to change the constraints implementation, or change something else that passes code to and from the bits that care about constraints, they should have to think about how the constraints are going to be passed in, and how to keep the performance of the constraint derivation high for whatever new thing they want to do. I think making it easy to ignore constraints is the wrong thing to do in this library, because (once merged) this library has committed to supporting them. I think if users of find-my-way want to not care about constraints, that's fine, they can just always pass undefined, but that's different than how we test and communicate to new contributors. That said, I don't want to be a stick in the mud, so if it's really important to you that the tests don't get updated I can go through and revert those changes. |
Yes, it's important. If both behaviors are supported, then the test should verify that. |
I agree its important, and there's tests that test the behaviour with and without the parameter. If that's all thats required we're good to merge, but are you saying you want all the test cases to implicitly test the undefined value, and then have only some tests that test with the value? |
ping @delvedor is the final decision to remove the parameter from all the tests or can we merge? |
Sorry to be a PITA, but if this pr is not changing the default behavior, those tests should not be updated. |
Again -- it isn't that the default behaviour hasn't changed, it has. Callers of |
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.
lgtm
ping @delvedor anything else you'd like to see before ? Would really like to get this in! |
…ardless of insertion order
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.
LGTM 🚀
@AyoubElk would you mind giving one last review? Then I think we're ready to merge! |
LGTM |
Co-authored-by: Ayoub El Khattabi <elkhattabi.ayoub@gmail.com>
Ok great -- anything left before merging? |
ping @delvedor can you hit the merge button? Or if there is anything outstanding let me know! |
I would just ship a major and then land the major update in FAstify. |
This is about fastify/fastify#2498 (host based routing), closes #165, replaces and closes #166. This is a completed version of @AyoubElk's changes in #166 that passes the tests!
This:
Accept-Version
route is passed, which requires lots of codeHost
header is equal to a string or passes a regexp testImplementation details:
find
now (must) take an object of constraint values derived from the request. Before, it took an optional version, but now there are many values, so it takes an object with aversion
key and or others. This is a weird API if you're callingfind
directly, but invisible if you're callinglookup
, which is what Fastify itself does. This is done to avoid extra checks and allocations for every route match. It also generates a lot of noise in this PR, sorry..handler
and a.versionStore
that store handlers separately, they have an array of handlers, and sometimes many constraint stores that know how to report which handlers should match which constraint values. The old version store is one, the host store is another, and userland code can create more.Constrainer
object that holds all the constraining strategies and that knows how to validate constraintsderivedConstraints
, which is the request host and theaccept-version
header most of the time isnew Function()
'd for speed since it is run for every request matchnew Function()
'd for each handler that has constraints, which creates a megamorphic callsite but only for constrainted handlers and in my testing is still faster than a monomorphic callsite with a loopNotably, there's a huge performance regression right now, especially on static route matching. First make it work, then make it fast they say, which I have been trying but failing to do, so I'd really love any assistance or even just theories about what is causing a big slow down. Currently a Draft PR until performance is brought back in line.
Would love your feedback on the code and specifically any pointers for where I screwed up the performance! On master I see roughly 45M static route matches a second, and I see 32M on this branch, so there's a lot of work yet to do.
The remaining work:
Also just FYI @AyoubElk and I have been coordinating on this off platform, I stepped in to complete the work so please direct your feedback on this feature to us here!