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-03-20
- Stars
- ★ 4
- 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
azure-apim-architecture
Analyzes and explains Azure API Management architecture decisions for enterprise API marketplace implementations using VNet Internal mode, Front Door, hybrid authentication, and multi-environment strategies. Use when discussing APIM component selection, network topology, cost optimization, or comparing alternatives like workspaces vs instances, VNet Internal vs External mode, or Front Door vs Application Gateway.
apiops-deployment
Guides deployment of Azure API Management infrastructure using Infrastructure as Code (Bicep/Terraform), CI/CD pipelines (GitHub Actions/Azure DevOps), and APIOps workflows. Use when deploying APIM, creating pipelines, or implementing dev→test→prod promotion strategies.
apim-policy-authoring
Creates production-ready Azure API Management policy XML for authentication (OAuth 2.0, JWT validation, subscription keys), rate limiting, CORS configuration, error handling, and API transformations. Use when implementing API security, access control, or request/response processing logic.
api-security-review
Reviews Azure API Management configurations for security vulnerabilities, OWASP API Security Top 10 compliance, VNet Internal mode validation, Private Link verification, and Azure Security Benchmark alignment. Use when performing security audits, pre-deployment validation, or compliance reviews.
jira-cli
Interact with Jira from the command line to create, list, view, edit, and transition issues, manage sprints and epics, and perform common Jira workflows. Use when the user asks about Jira tasks, tickets, issues, sprints, or needs to manage project work items.
calculator
Performs arbitrary-precision arithmetic calculations including addition, subtraction, multiplication, division, and exponents. Use when the user asks to calculate, compute, or evaluate math expressions, or when precise decimal arithmetic is needed to avoid floating-point errors.