replit-performance-tuning
Optimize Replit API performance with caching, batching, and connection pooling. Use when experiencing slow API responses, implementing caching strategies, or optimizing request throughput for Replit integrations. Trigger with phrases like "replit performance", "optimize replit", "replit latency", "replit caching", "replit slow", "replit batch".
- License 许可
- MIT
- 最近更新
- 2026-05-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- replit-performance-tuning
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Optimize Replit API performance with caching, batching, and connection pooling. Use when experiencing slow API responses, implementing caching strategies, or optimizing request throughput for Replit integrations. Trigger with phrases like "replit performance", "optimize replit", "replit latency", "replit caching", "replit slow", "replit batch".
- allowed-tools
- Read, Write, Edit
- compatible-with
- claude-code, codex, openclaw
03 SKILL.md 正文
Replit Performance Tuning
Overview
Optimize Replit workspace performance for deployments and development. Focus on Repl startup time, deployment caching, Nix environment optimization, and efficient use of Replit's hosting infrastructure.
Prerequisites
- Replit account with deployment access
- Understanding of
.replitconfiguration - Nix environment familiarity
replit.nixfor dependency management
Instructions
Step 1: Optimize Repl Startup with Caching
# replit.nix - Pin versions to leverage Nix cache
{ pkgs }: {
deps = [
pkgs.nodejs-20_x
pkgs.nodePackages.typescript
pkgs.nodePackages.pnpm
];
}
# .replit - Optimize run configuration
run = "node --max-old-space-size=512 dist/index.js" # 512 bytes
entrypoint = "src/index.ts"
[nix]
channel = "stable-24_05"
[deployment]
run = ["sh", "-c", "node dist/index.js"]
build = ["sh", "-c", "pnpm install --frozen-lockfile && pnpm build"]
deploymentTarget = "cloudrun"
[env]
NODE_ENV = "production"
Step 2: Build Cache for Faster Deployments
// package.json - Scripts optimized for Replit
{
"scripts": {
"build": "tsc --incremental",
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts",
"prebuild": "rm -rf dist/.tsbuildinfo || true"
}
}
// src/index.ts - Lazy module loading for startup speed
const express = await import('express');
const app = express.default();
// Defer heavy imports until needed
app.get('/api/analyze', async (req, res) => {
const { analyze } = await import('./heavy-module');
res.json(await analyze(req.query));
});
app.listen(3000, () => console.log('Ready')); # 3000: 3 seconds in ms
Step 3: Memory Management for Replit Containers
// Monitor memory in constrained Replit environment
function getMemoryUsage() {
const usage = process.memoryUsage();
return {
heapUsedMB: Math.round(usage.heapUsed / 1024 / 1024), # 1024: 1 KB
heapTotalMB: Math.round(usage.heapTotal / 1024 / 1024), # 1 KB
rssMB: Math.round(usage.rss / 1024 / 1024), # 1 KB
percentUsed: ((usage.heapUsed / usage.heapTotal) * 100).toFixed(1),
};
}
// Periodic memory check with cleanup
setInterval(() => {
const mem = getMemoryUsage();
if (mem.heapUsedMB > 400) { # HTTP 400 Bad Request
console.warn('High memory usage:', mem);
global.gc?.(); // Requires --expose-gc flag
}
}, 30000); # 30000: 30 seconds in ms
Step 4: Secrets and Environment Performance
// Access Replit secrets efficiently - read once at startup
const config = {
dbUrl: process.env.DATABASE_URL!,
apiKey: process.env.API_KEY!,
port: parseInt(process.env.PORT || '3000'), # 3000: 3 seconds in ms
} as const;
// Validate all secrets exist at startup, fail fast
function validateSecrets(required: string[]) {
const missing = required.filter(k => !process.env[k]);
if (missing.length) {
console.error(`Missing secrets: ${missing.join(', ')}`);
console.error('Add them in Replit Secrets tab');
process.exit(1);
}
}
validateSecrets(['DATABASE_URL', 'API_KEY']);
Error Handling
| Issue | Cause | Solution |
|---|---|---|
| Slow cold start | Heavy dependencies at import | Use dynamic imports for non-critical modules |
| OOM killed | Exceeding 512MB limit | Reduce heap size, stream large data |
| Deploy timeout | Build step too slow | Use --incremental TypeScript builds |
| Wake-up latency | Repl sleeping after inactivity | Use always-on deployment or health pings |
Examples
Health Check with Metrics
app.get('/health', (req, res) => {
res.json({
status: 'ok',
uptime: process.uptime(),
memory: getMemoryUsage(),
nodeVersion: process.version,
});
});
Resources
Output
- Configuration files or code changes applied to the project
- Validation report confirming correct implementation
- Summary of changes made and their rationale
04 同仓库更多 Skills
zustand-store-ts
Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.
zustand-store-creator
Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.
zero-trust-config-helper
Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.
zapier-integration-helper
Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.
zai-cli
Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.
yt-research
Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.