klein icon indicating copy to clipboard operation
klein copied to clipboard

Klein adds significant performance overhead over a twisted.web server

Open itamarst opened this issue 1 year ago • 6 comments

A minimal hello world benchmark, just routing "/" and returning a string, is half the speed of the equivalent minimal twisted.web server.

I will start investigating where the performance overhead is, and hopefully find some places to optimize.

itamarst avatar May 31 '24 12:05 itamarst

Initial investigation suggests no obvious Klein-side improvements, other than a minor 1% improvements. Possibly would benefit from additional performance optimizations on the Twisted side though that weren't exposed by previous benchmarks.

itamarst avatar May 31 '24 13:05 itamarst

Is klein designed to be used for high performance applications ?

I see klein and other similar "microframework" as a quick way to get a simple site up and runnig, without the expectation of performance or doing advance/custome HTTP operations.

adiroiban avatar May 31 '24 17:05 adiroiban

Is klein designed to be used for high performance applications ?

If it's for use in production then it should be as fast as is reasonable.

glyph avatar Jun 01 '24 05:06 glyph

I will start investigating where the performance overhead is, and hopefully find some places to optimize.

How much of it is happening in Klein vs. e.g. Werkzeug?

glyph avatar Jun 01 '24 06:06 glyph

Werkzeug is pretty minimal. It's mostly additional twisted.web interactions (therefore places where twisted.web optimizations might help), twisted Deferreds, and the fact that klein is very forgiving in what you can return. Architectural improvements for the latter might involve looking at function return signatures and assuming they're accurate, maybe, so you don't have to all the if IResource.providedBy stuff.

itamarst avatar Jun 01 '24 14:06 itamarst

And it's also possible there's work being done on in klein that's duplicative to what twisted.web does.

itamarst avatar Jun 01 '24 14:06 itamarst