JIT Compiler
Byte includes a JIT compiler for inlining method calls.
Here is an example application:
The route will be stored as:
With the JIT compiler the route execution can be simplified to:
This reduces the amount of unnecessary checks the handlers need to do at request time.
The compiler can optimize even more in these cases:
- If a function has no parameter then do not pass
ctx
as an argument. - If a function is not asynchronous then remove
await
. - If no functions have parameters then the
run
function does not needctx
as a parameter. - If no functions are asynchronous then the
run
function can be synchronous.
The source code of the compiler can be seen here.
Route matching
The route matching phase uses the Blitz router, which compiles the routes into an optimized matching function. You can skip JIT compilation for this phase by using EdgeRouter.