Performance: Why production Deno needs careful architecture
This affects server response time, resource usage, and overall app scalability in production environments.
import { serve } from "https://deno.land/std/http/server.ts"; const handler = async (req) => { // Offload heavy task to a worker or async process await someAsyncHeavyTask(); return new Response("Done"); }; serve(handler);
import { serve } from "https://deno.land/std/http/server.ts"; const handler = (req) => { // Heavy synchronous computation blocking event loop for (let i = 0; i < 1e9; i++) {} return new Response("Done"); }; serve(handler);
| Pattern | Event Loop Blocking | Startup Time | Memory Usage | Verdict |
|---|---|---|---|---|
| Heavy synchronous tasks in handler | Blocks event loop | Fast startup | High memory | [X] Bad |
| Async handler with offloaded tasks | Non-blocking | Fast startup | Optimized memory | [OK] Good |
| Importing full large libraries | No event loop impact | Slow startup | High memory | [X] Bad |
| Selective imports of needed functions | No event loop impact | Fast startup | Low memory | [OK] Good |
| Synchronous file I/O in request handler | Blocks event loop | No startup impact | Moderate memory | [X] Bad |
| Async file I/O in request handler | Non-blocking | No startup impact | Moderate memory | [OK] Good |
try {
const data = await Deno.readTextFile('config.json');
console.log('Config loaded:', data);
} catch (error) {
console.error('Failed to load config:', error.message);
}config.json does not exist and the script is run with deno run --allow-read script.ts?const data = await Deno.readTextFile('data.txt');
console.log(data);deno run script.ts without any flags, what error will you get?Pass the test and this pattern moves unknown