Optimize your app for 250,000+ req/sec.
CanxJS is already fast, but these tips will push it to the limit.
CanxJS includes an experimental JIT compiler for routes. Enable it in config:
// src/config/app.ts
export const config = {
jit: true,
};Avoid N+1 queries by using eager loading:
// Bad
const posts = await Post.all();
for (const post of posts) {
await post.load("author"); // N+1 query
}
// Good
const posts = await Post.with("author").get();Use the built-in Redis cache for expensive operations:
import { Cache } from "canxjs";
const stats = await Cache.remember("dashboard_stats", 60, async () => {
return calculateHeavyStats();
});Have questions?
Join the discussion on GitHub