Skip to content
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

hono/build #3659

Open
EdamAme-x opened this issue Nov 12, 2024 · 16 comments
Open

hono/build #3659

EdamAme-x opened this issue Nov 12, 2024 · 16 comments

Comments

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Nov 12, 2024

I'm creating a new router named "PreparedRouter" using AOT.
This issue is a thread to solicit opinions on concerns.

@yusukebe
Copy link
Member

yusukebe commented Nov 12, 2024

Quick response.

Rather than AOT, it would be nice to have a build script or bundler that writes out an optimal application "file" that includes the hono. Then, it will work in Cloudflare Workers and other environments where eval and Function are not available.

@yusukebe
Copy link
Member

yusukebe commented Nov 12, 2024

I forgot, but we discussed this issue - creating a build script or bundler - in this project Issue or PR with @usualoma.

@EdamAme-x
Copy link
Contributor Author

EdamAme-x commented Nov 12, 2024

I have seen PreparedRegExpRouter in the past.
I've seen the whole discussion, but it seems difficult to interfere with the build.

And you as said, it currently depends on Function, so it won't work with Cloudflare workers, etc.
However, I think it will help speed things up in VPS and other environments.

@MathurAditya724
Copy link
Contributor

I’ve also been considering a feature like this for Hono, and I agree with @yusukebe on incorporating a build script. I recall we previously discussed this topic while comparing the speeds of Hono and Elysia with AOT compilation.

Rather than embedding this directly into the router, integrating it into something like Honox might be more effective. The code/logic is already modularized with nested routes, allowing us to implement a script that merges these routes into a single, optimized Hono app. This approach could enhance performance across different runtimes.

The key question now is which specific optimizations we could include in the build script to maximize efficiency. Thoughts?

@EdamAme-x
Copy link
Contributor Author

EdamAme-x commented Nov 12, 2024

Even if we choice to build, we need the logic of code generation for optimization, so we will work on PreparedRouter.
Also, the following may be of use.

new PreparedRouter({
  preparedMatch: () => {
    ...
  } // precompiled
})

It should be able to be utilized when build.

@ryuapp
Copy link
Contributor

ryuapp commented Nov 12, 2024

I don't know if that's possible, but if we can make good use of Parcel's macros, the prepared router will seem to make sense.
https://parceljs.org/features/macros/

The macros also work with Vite etc.
https://github.com/devongovett/unplugin-parcel-macros

@yusukebe
Copy link
Member

But, IMO, we don't have to implement the PreparedRouter or build a script or bundler (just for a "router") because our routers are already fast enough. If we have a faster router, it may not affect us in the real world.

@usualoma
Copy link
Member

I'm also interested in this area, and it's worth considering if there is a good approach. I'm also interested in macros.

The reasons I considered this with "honox" before are as follows.

  • Going through the build process
  • Routing being determined statically

It isn't easy to prepare for apps that don't use static routing (use variables). I think that apps that use variables are in the minority, but I think it's inevitable that there will be conditions that determine whether or not they can be applied.

There are currently hono, hono/quick, and hono/tiny, and they meet most requirements. So, I think the difficult part is whether or not we can prepare something that makes sense to add to them.

@yusukebe
Copy link
Member

What do you think about anything other than routing?

For example, define a schema for the incoming JSON. After building the app, an optimized JSON parser is written in the build script. The parsing is then much faster than normally using JSON.parse.

@MathurAditya724
Copy link
Contributor

some initial ideas -

  • Combine all chained validators into a single, unified validator during the build process.
  • Implement a handler that pre-generates responses at build time for faster delivery, taking a similar approach to static site generation.
  • Move toward compiling all components at build time for improved efficiency.

@yusukebe
Copy link
Member

Haha, topics are getting bigger! But I have the most fun when we talk about these things.

@nakasyou
Copy link
Contributor

For example, define a schema for the incoming JSON. After building the app, an optimized JSON parser is written in the build script. The parsing is then much faster than normally using JSON.parse.

It is why elysia is fast. I want Hono to implement it.

And my personal opinion, build-time building is better than run-time building. Outputting code can reduce build size.

@yusukebe
Copy link
Member

It is why elysia is fast.

Yes, exactly (though I don't want to fight with Elysia).

@EdamAme-x
Copy link
Contributor Author

EdamAme-x commented Nov 15, 2024

hono/build is interesting for me.
It has the potential to become a hot topic for v5.

@nakasyou
Copy link
Contributor

In the future it may depend external package such as TypeScript compiler API and babel. So I think it should be in hono/middleware or other repo, and create @hono/build.

@yusukebe
Copy link
Member

In the future it may depend external package such as TypeScript compiler API and babel. So I think it should be in hono/middleware or other repo, and create @hono/build.

+1

@EdamAme-x EdamAme-x changed the title feat(router): Introduce PreparedRouter hono/build Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants