Skip to content

Instantly share code, notes, and snippets.

View patrickalima98's full-sized avatar

Patrick A Lima patrickalima98

View GitHub Profile
@patrickalima98
patrickalima98 / hono-lazy-load-readme.md
Last active January 11, 2024 02:51
Lazy load engine for Deno and Hono

Hono Lazy loader

This is a simple and rudmentar prototyping of a lazy loader for Hono to be used with Deno and Deno Deploy. Maybe can be adapated for others runtimes.

Why?

Pushing the limits of what is possible with Deno Deploy, I developed a moderately small Api service (44 files, 10 endpoints and 3 handlers). The project supports Postgres with Drizzle, called postgres and redis. However, as the project scaled and more libraries were added I began to experience very long cold starts, an inconsistent average of (4 - 15sec).

After many tests I verified that there was a bottleneck in loading the files (handlers), deno deploy started taking a long time to load the files, when eliminating the imports the problem disappeared, in essence Hono does not support Lazy Loading, this gist provides a prototype for that. When initializing, a standard and generic server will be loaded, only importing when the current route handler is requested.