patrickalima98
patrickalima989mo ago

How to optimize imports on deno deploy?

I have a medium project (44 files) deployed on deno deploy, where works. But, I'm getting inconsistent and sometimes very long cold start times in my deno project, like the attached image. All my dependencies:
{
"std/": "https://deno.land/std@0.205.0/",
"hono/": "https://deno.land/x/hono@v3.9.2/",
"fs/": "https://deno.land/std@/fs/",
"dotenv": "npm:dotenv",
"drizzle-orm": "npm:drizzle-orm",
"drizzle-kit": "npm:drizzle-kit",
"drizzle-orm/sqlite-core": "npm:drizzle-kit",
"@vinejs/vine": "npm:@vinejs/vine",
"@vinejs/compiler/types": "https://cdn.jsdelivr.net/npm/@vinejs/compiler@2.2.0/build/src/types.d.ts",
"uuidv4": "npm:uuidv4",
"rambda": "npm:rambda",
"hasha": "npm:hasha",
"upstash_redis": "https://deno.land/x/upstash_redis@v1.14.0/mod.ts",
"ioredis": "npm:ioredis",
"dayjs": "npm:dayjs",
"drizzle-typebox": "npm:drizzle-typebox",
"@sinclair/typebox": "npm:@sinclair/typebox",
"drizzle-orm/pg-proxy": "npm:drizzle-orm/pg-proxy",
"postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts"
}
{
"std/": "https://deno.land/std@0.205.0/",
"hono/": "https://deno.land/x/hono@v3.9.2/",
"fs/": "https://deno.land/std@/fs/",
"dotenv": "npm:dotenv",
"drizzle-orm": "npm:drizzle-orm",
"drizzle-kit": "npm:drizzle-kit",
"drizzle-orm/sqlite-core": "npm:drizzle-kit",
"@vinejs/vine": "npm:@vinejs/vine",
"@vinejs/compiler/types": "https://cdn.jsdelivr.net/npm/@vinejs/compiler@2.2.0/build/src/types.d.ts",
"uuidv4": "npm:uuidv4",
"rambda": "npm:rambda",
"hasha": "npm:hasha",
"upstash_redis": "https://deno.land/x/upstash_redis@v1.14.0/mod.ts",
"ioredis": "npm:ioredis",
"dayjs": "npm:dayjs",
"drizzle-typebox": "npm:drizzle-typebox",
"@sinclair/typebox": "npm:@sinclair/typebox",
"drizzle-orm/pg-proxy": "npm:drizzle-orm/pg-proxy",
"postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts"
}
After some tests, I suspect there is a problem with Imports, because only to import a module with 5x files the deploy is having 2 secs, sometimes 4 secs. I would like to know if this is normal and if not, How can i fix it?
No description
6 Replies
patrickalima98
patrickalima989mo ago
This is other big cold start:
patrickalima98
patrickalima989mo ago
No description
raunioroo
raunioroo9mo ago
I'm not that familiar with deploy, but many npm packages tend to be huuuuuge. eg. drizzle here is 5mb of code, vine 2mb. it doesn't matter how many files your project is, if your npm deep dependencies are 100x-1000x that (i guess that's the nature of npm ecosystem) - not that surprising if cold starts are high. Libraries made specifically for deno tend to be much smaller. But again I'm not sure if there are ways to optimize that on deploy. Just my personal experience; it's best to bring from npm only what you absolutely need and can't find elsewhere.
patrickalima98
patrickalima989mo ago
Maybe you're right. I'll try do some lazy load for my handlers based in the route to see if I can get some result. Maybe it can help
patrickalima98
patrickalima989mo ago
Create a lazy loading system give better results. However after 24 hours, I get random and some times long long very cold start.
No description
patrickalima98
patrickalima989mo ago
This problem its not 100% for all locations. For example the first request of the day for us-east-4 and europe in general is acceptable. The main problem is in the south america