Performance¶
This section covers performance characteristics, optimization techniques, and benchmarking methodologies for INFINITY.JS applications.
Overview¶
INFINITY.JS is designed for high-performance server applications with:
- Multi-threaded Architecture: True parallel execution with isolated MuJS engine instances per thread
- Script and Bytecode Caching: Scripts and compiled bytecode are cached, so request scripts don't have to be loaded and compiled again
- Native Extensions: C/C++ and Delphi/Pascal extensions for performance-critical code
- Pooling: Thread pool of the HTTP server and connection pooling for databases
- Vector Search: Exact search or IVF (inverted file) index with SIMD-accelerated vector operations
Measured with an earlier version
The figures on this page and on the Benchmarks page were measured with an earlier version of INFINITY.JS and have not been verified with the current release. Parts of them describe features that the current runtime doesn't have (e.g. an HNSW index in infinity.vectordb). Use them as rough orientation only and measure your own workload.
Performance Topics¶
Benchmarks¶
Comprehensive performance benchmarks for key modules:
- HTTP Server: Requests per second, latency, concurrent connections
- Database: Query performance, transaction throughput, connection pooling impact
- Vector Database: Search performance, indexing speed, parameter tuning
- Multi-threading: Parallel processing speedup and scaling efficiency
- Memory: Allocation, garbage collection, shared memory performance
Each benchmark includes: - Reproducible test code - Performance results across different configurations - Hardware specifications and methodology - Optimization recommendations
Performance Best Practices¶
HTTP Server¶
Thread Pool Sizing:
// CPU-intensive workloads
let cpuServer = new infinity.http.server(false, false, false, false, false,
8080, 2048, infinity.os.processorCount); // poolSize = CPU cores
// I/O-intensive workloads
let ioServer = new infinity.http.server(false, false, false, false, false,
8081, 2048, infinity.os.processorCount * 4); // poolSize = 2-4× CPU cores
Enable Compression Selectively: - Enable for text/JSON responses > 1KB - Disable for pre-compressed content (images, videos) - Monitor CPU impact in production
Connection Management: - Set maxConnections high enough for peak traffic - Monitor connection queue depth - Use load balancing for > 10K concurrent connections
Database¶
Use Transactions for Batch Operations:
// Fast: Single transaction for batch
db.startTransaction();
for (let i = 0; i < 10000; i++) {
db.execute('INSERT INTO ...');
}
db.commit();
// ~12 ms for 10K inserts
// Slow: Auto-commit per operation
for (let i = 0; i < 10000; i++) {
db.execute('INSERT INTO ...');
}
// ~2,200 ms for 10K inserts (183× slower!)
Enable Connection Pooling:
// Set before connect()
db.pooling = true;
db.minPoolSize = 5;
db.maxPoolSize = 20;
Parameterized Queries:
// Always use parameters (prevents SQL injection, enables caching)
db.sql = 'SELECT * FROM users WHERE id = :id';
db.setParamValue('id', userId);
db.execute();
Vector Database¶
Index Parameter Selection:
The vector database has no HNSW index. Performance and accuracy are controlled by the parameters of infinity.vectordb.open() (see infinity.vectordb):
| Parameter | Effect |
|---|---|
ivfEnabled | false: exact search over all vectors (best accuracy, fine for small datasets); true: IVF index for large datasets |
ivfNumClusters | Number of IVF clusters, typically about sqrt(maxItems) |
ivfNProbe | Clusters searched per query (typically 1-10 % of the clusters) - higher is more accurate but slower |
parallelSearchThreads | Threads per search (typically 1-4) |
dimensions | Memory and search time grow linearly with the dimensions |
Batch Vector Additions:
// Efficient: Batch additions
let vectors = [];
for (let i = 0; i < 10000; i++) {
vectors.push({ id: i, vector: generateVector() });
}
for (let item of vectors) {
infinity.vectordb.add('index', item.id, item.vector);
}
Multi-threading¶
When to Use Threads: - CPU-intensive computations (image processing, encryption) - I/O-bound operations (file scanning, network requests) - Background tasks (cleanup, monitoring, indexing)
Thread Count Guidelines: - CPU-bound: Number of CPU cores - I/O-bound: 2-4× CPU cores - Measure and tune for your workload
Avoid: - Creating threads for short-lived tasks (overhead > benefit) - Excessive thread counts (> 4× CPU cores) - Shared state without proper synchronization
Profiling Tools¶
Built-in Logging¶
Slow Request Logging:
let server = new infinity.http.server(
false, false, false, false, true,
8080, 2048, 64, 1024 * 1024,
2.0 // slowRequestTime: log requests > 2 seconds
);
Access Logging:
let server = new infinity.http.server(
false, false, false, false,
true, // accessLog: log all requests
8080
);
External Tools¶
HTTP Load Testing:
The release archive contains benchmark tools in tools/bench. Other common tools:
# wrk - Modern HTTP benchmarking
wrk -t12 -c400 -d30s http://localhost:8080/
# Apache Bench - Classic tool
ab -n 100000 -c 100 http://localhost:8080/
# hey - Go-based load generator
hey -n 100000 -c 200 http://localhost:8080/
System Monitoring:
# Process CPU and memory
top -p $(pgrep infinity)
# Detailed statistics
pidstat -p $(pgrep infinity) 1
# I/O monitoring
iotop -p $(pgrep infinity)
# Network statistics
netstat -tnp | grep infinity
Performance Checklist¶
Before deploying to production:
- HTTP Server: Right-sized thread pool for workload type
- Database: Connection pooling enabled
- Database: Transactions used for batch operations
- Database: Indexes on frequently queried columns
- Vector DB: IVF parameters tuned for accuracy/speed trade-off
- Compression: Enabled for appropriate content types
- Connection Limits: Set based on expected peak load
- Slow Request Logging: Enabled to identify bottlenecks
- Load Testing: Conducted under realistic traffic patterns
- Monitoring: System metrics tracked (CPU, memory, connections)
Optimization Workflow¶
- Measure: Establish baseline performance metrics
- Identify: Find bottlenecks using profiling and logging
- Optimize: Apply targeted optimizations
- Verify: Re-measure to confirm improvements
- Iterate: Repeat for remaining bottlenecks
Remember: Premature optimization is the root of all evil. Always measure before optimizing.
Additional Resources¶
- Benchmarks - Detailed performance benchmarks
- HTTP Architecture - Thread pool architecture
- Database API - Database operations
- Vector Database API - Vector search operations
- Thread API - Multi-threading
Performance Goals¶
Typical performance targets for INFINITY.JS applications:
| Metric | Target | Notes |
|---|---|---|
| HTTP RPS (static) | 50,000+ | 64 threads, no compression |
| HTTP RPS (dynamic) | 20,000+ | 64 threads, with database |
| HTTP P99 latency | < 50 ms | Under normal load |
| Database queries/sec | 50,000+ | SQLite, with transactions |
| Vector search QPS | 200+ | 100K vectors, 384 dims |
| Thread scaling | 7-8× | 8 cores, CPU-bound work |
Actual performance depends on hardware, workload, and configuration. These targets have not been verified with the current release. Always benchmark your specific use case.