Sanic: consider using Routes for routing

Created on 16 Sep 2018  路  18Comments  路  Source: sanic-org/sanic

Routes https://routes.readthedocs.io/en/latest/ is a mature router implementation that focuses on URL routing and nothing more.

idea discussion necessary

Most helpful comment

@ahopkins uvloop and ujson are already compiled dependencies. The decision was already made to favor speed. I say go for it.

All 18 comments

Do you have any benchmarks? What benefits would you see for adopting this over the existing solution? I'm personally in favor of keeping external dependencies as slim as possible. While the sanic router could use some work, and is generally rather performant, I would not be in favor of adding a third party package. I know of a few other alternative ideas floating around.

@petri @ahopkins tomorrow I'll probably have a good benchmark suite over some known (and lesser known) URL routers for Python :wink:

@petri I wrote a small benchmark suite for testing different routing systems in Python. Here's the repository. I don't believe Routes is a good choice and, if a mature routing system is to be considered, then I would really consider Falcon's.

@vltr nice work! Thanks for sharing.

I agree with @vltr but I will claim bias as I migrated to Sanic from Falcon.

@sjsadowski yeah, well, I'm glad this benchmark is just for the router :smile:

Being "pure Python", the Falcon router really does a good job (Sanic does too, but with a lot of regex and high complexity searches, yet still error prone in some situations).

Since we are on the topic ...

I'm curious to hear how people would react to using C extensions or cython in situations like this one to gain some more performance.

@ahopkins not only performance may I add; the Sanic router, like I said, might be error prone in some situations exactly because of its complexity (and flexibility). I know very well that it was (made this way) with the best of intentions, but this might be a trade-off between having such flexibility on the router _or_ have a fast and reliable router ... It's hard to choose :sweat_smile:

I tend to prefer flexibility over speed here (blasphemy?) because aside from everything else, we're still functioning at web-speed. I think also moving to an extension - that would be compiled - starts to increase difficulty of adoption for people who may not have access or support to build extensions.

No blasphemy at all. I believe that a compiled extension is on the table because we already depend on some (httptools, multidict). The point is the cost of having such flexibility on the router to be error prone and overly complex to maintain.

I was not proposing compilation for users of Sanic, but before the release (hence whoever it is that is going to work on the development of the router). We can pre-compile and just import as if it were written in Python.

I agree with @vltr but I will claim bias as I migrated to Sanic from Falcon.

Not alone in that quest!

@ahopkins uvloop and ujson are already compiled dependencies. The decision was already made to favor speed. I say go for it.

@ahopkins @vltr do we want to keep this open?

@sjsadowski yes, I think it's good to leave it open and start a further discussion in the community forum since our current Router (and overall Request workflow (see #1317 and related issues)) really needs some attention - either from the performance perspective to the complexity perspective, design and etc.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.

Related discussion here: https://community.sanicframework.org/t/making-sanic-even-faster/298?u=ahopkins

This is on my radar after ASGI.

Closing this. The forums have plenty more information about this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aiurlano picture aiurlano  路  4Comments

olalonde picture olalonde  路  3Comments

woutor picture woutor  路  3Comments

fiecato picture fiecato  路  3Comments

Souldat picture Souldat  路  3Comments