Performance Benchmarks¶
This section provides performance benchmarks and testing methodologies for key INFINITY.JS modules. These benchmarks help you understand expected performance characteristics and optimize your applications.
Measured with an earlier version
The results on this page were measured with an earlier version of INFINITY.JS on the reference system below and have not been verified with the current release. In particular, the vector database sections refer to an HNSW index with the parameters M, efConstruction and efSearch, which the current infinity.vectordb module doesn't have (it offers exact search and an IVF index). The code samples have been updated to the current API. Treat all numbers as rough orientation and measure your own workload, e.g. with the tools in tools/bench of the release archive.
Benchmark Environment¶
All benchmarks were conducted on the following reference system unless otherwise noted:
Hardware: - CPU: Intel Core i7-10700K (8 cores, 16 threads @ 3.8 GHz) - RAM: 32 GB DDR4-3200 - Storage: Samsung 970 EVO Plus NVMe SSD - Network: 1 Gbps Ethernet
Software: - OS: Windows 10 Pro / Ubuntu 22.04 LTS - INFINITY.JS: Version 3.0 (check your version with infinity.version)
HTTP Server Benchmarks¶
Requests Per Second (RPS)¶
Testing HTTP server throughput with various handler types and configurations.
Benchmark Code¶
// benchmark-http.ts
infinity.loadModule('infinity.http');
let requestCount = 0;
let startTime = Date.now();
// Simple JSON response handler
let server = new infinity.http.server(false, false, false, false, false, 8080, 2048, 64);
server.registerHandler(infinity.http.server.handler.jsonRpc, '/api/test');
server.registerService('benchmark', 'benchmark', 'benchmark.js', [
{ name: 'echo', params: ['message: string'], result: 'object' }
]);
server.start();
console.info('HTTP Benchmark Server started on port 8080');
console.info('Run: wrk -t12 -c400 -d30s http://localhost:8080/api/test');
while (!infinity.terminated) {
infinity.sleep(1000);
}
server.stop();
// benchmark.ts
namespace benchmark {
export function echo(message: string): object {
return {
success: true,
message: message,
timestamp: Date.now()
};
}
}
Results¶
Static File Handler: | Configuration | RPS | Latency (avg) | Latency (p99) | |---------------|-----|---------------|---------------| | poolSize=16, compression=off | 45,000 | 8.5 ms | 25 ms | | poolSize=32, compression=off | 62,000 | 6.2 ms | 18 ms | | poolSize=64, compression=off | 78,000 | 5.1 ms | 15 ms | | poolSize=32, compression=on | 38,000 | 10.5 ms | 32 ms |
JSON-RPC Handler (Simple Echo): | Configuration | RPS | Latency (avg) | Latency (p99) | |---------------|-----|---------------|---------------| | poolSize=16 | 38,000 | 10.2 ms | 28 ms | | poolSize=32 | 52,000 | 7.4 ms | 22 ms | | poolSize=64 | 68,000 | 5.8 ms | 17 ms |
REST Handler (Database Query): | Configuration | RPS | Latency (avg) | Latency (p99) | |---------------|-----|---------------|---------------| | poolSize=16, db pooling=on | 12,000 | 32 ms | 85 ms | | poolSize=32, db pooling=on | 18,500 | 21 ms | 62 ms | | poolSize=64, db pooling=on | 22,000 | 18 ms | 54 ms |
Load Testing Commands¶
# Using wrk (HTTP benchmarking tool)
wrk -t12 -c400 -d30s http://localhost:8080/static/index.html
# Using Apache Bench
ab -n 100000 -c 100 http://localhost:8080/api/test
# Using hey
hey -n 100000 -c 200 -m POST -d '{"jsonrpc":"2.0","method":"benchmark.echo","params":["test"],"id":1}' \
-H "Content-Type: application/json" \
http://localhost:8080/api/test
Concurrent Connections¶
Testing maximum sustainable concurrent connections:
| maxConnections | poolSize | Sustained RPS | Memory Usage | CPU Usage |
|---|---|---|---|---|
| 1,024 | 32 | 45,000 | 680 MB | 75% |
| 2,048 | 64 | 68,000 | 1.2 GB | 92% |
| 4,096 | 128 | 82,000 | 2.1 GB | 98% |
Note: Performance degrades when connections exceed poolSize × 32 due to queueing overhead.
Database Benchmarks¶
Query Performance¶
Testing database operations with SQLite, MySQL, and PostgreSQL.
Benchmark Code¶
// benchmark-database.ts
infinity.loadModule('infinity.database');
function benchmarkQueries(iterations: number): void {
let db = new infinity.database();
try {
db.specificOptions['Direct'] = true;
db.connect(infinity.database.provider.sqlite, '', 0, 'benchmark.db');
// Create test table
db.execute('DROP TABLE IF EXISTS benchmark_test');
db.execute('CREATE TABLE benchmark_test (id INTEGER PRIMARY KEY, data TEXT, value INTEGER)');
// Benchmark: INSERT
let startTime = Date.now();
db.startTransaction();
for (let i = 0; i < iterations; i++) {
db.sql = 'INSERT INTO benchmark_test (data, value) VALUES (:data, :value)';
db.setParamValue('data', 'test data ' + i);
db.setParamValue('value', i);
db.execute();
}
db.commit();
let insertTime = Date.now() - startTime;
console.info(`INSERT: ${iterations} rows in ${insertTime}ms (${(iterations / insertTime * 1000).toFixed(0)} ops/sec)`);
// Benchmark: SELECT
startTime = Date.now();
for (let i = 0; i < iterations; i++) {
db.sql = 'SELECT * FROM benchmark_test WHERE id = :id';
db.setParamValue('id', i % iterations);
db.execute();
let result = db.result('data');
}
let selectTime = Date.now() - startTime;
console.info(`SELECT: ${iterations} queries in ${selectTime}ms (${(iterations / selectTime * 1000).toFixed(0)} ops/sec)`);
// Benchmark: UPDATE
startTime = Date.now();
db.startTransaction();
for (let i = 0; i < iterations / 10; i++) {
db.sql = 'UPDATE benchmark_test SET value = :value WHERE id = :id';
db.setParamValue('value', i * 2);
db.setParamValue('id', i);
db.execute();
}
db.commit();
let updateTime = Date.now() - startTime;
console.info(`UPDATE: ${iterations / 10} rows in ${updateTime}ms (${(iterations / 10 / updateTime * 1000).toFixed(0)} ops/sec)`);
db.disconnect();
} finally {
db.free();
}
}
benchmarkQueries(10000);
Results¶
SQLite (Direct Mode): | Operation | Operations/sec | Notes | |-----------|----------------|-------| | INSERT (with transaction) | 85,000 | Batch inserts in single transaction | | INSERT (auto-commit) | 450 | One transaction per insert | | SELECT (indexed) | 125,000 | Primary key lookup | | SELECT (non-indexed) | 8,500 | Full table scan (10K rows) | | UPDATE (with transaction) | 72,000 | Batch updates in single transaction | | DELETE (with transaction) | 78,000 | Batch deletes in single transaction |
MySQL (Pooling Enabled): | Operation | Operations/sec | Notes | |-----------|----------------|-------| | INSERT (with transaction) | 42,000 | Batch inserts | | SELECT (indexed) | 68,000 | Primary key lookup | | SELECT (JOIN, 2 tables) | 12,500 | Simple JOIN on indexed columns | | UPDATE (with transaction) | 38,000 | Batch updates |
PostgreSQL (Pooling Enabled): | Operation | Operations/sec | Notes | |-----------|----------------|-------| | INSERT (with transaction) | 48,000 | Batch inserts | | SELECT (indexed) | 72,000 | Primary key lookup | | SELECT (JOIN, 2 tables) | 14,000 | Simple JOIN on indexed columns | | UPDATE (with transaction) | 41,000 | Batch updates |
Connection Pooling Impact¶
| Configuration | Query Latency (avg) | Throughput Improvement |
|---|---|---|
| Pooling OFF | 45 ms | Baseline |
| Pooling ON (5 connections) | 8 ms | 5.6× faster |
| Pooling ON (10 connections) | 5 ms | 9× faster |
| Pooling ON (20 connections) | 4.5 ms | 10× faster |
Recommendation: Enable pooling for all production workloads. Set pool size to match expected concurrent database operations.
Transaction Performance¶
// Benchmark: Transaction vs Auto-Commit
function benchmarkTransactions(): void {
let db = new infinity.database();
try {
db.specificOptions['Direct'] = true;
db.connect(infinity.database.provider.sqlite, '', 0, 'benchmark.db');
// WITHOUT transaction (auto-commit)
let start = Date.now();
for (let i = 0; i < 1000; i++) {
db.execute('INSERT INTO test VALUES (' + i + ')');
}
console.info('Auto-commit: ' + (Date.now() - start) + 'ms');
// WITH transaction
start = Date.now();
db.startTransaction();
for (let i = 0; i < 1000; i++) {
db.execute('INSERT INTO test VALUES (' + i + ')');
}
db.commit();
console.info('Transaction: ' + (Date.now() - start) + 'ms');
db.disconnect();
} finally {
db.free();
}
}
Results: - Auto-commit (1,000 inserts): ~2,200 ms - Single transaction (1,000 inserts): ~12 ms - Speedup: 183× faster with transactions
Vector Database Benchmarks¶
Search Performance (HNSW Index)¶
Outdated
The HNSW results and the HNSW parameter tuning below don't apply to the current infinity.vectordb module, which has no HNSW index. They are kept for reference only.
Testing semantic search operations with various vector dimensions and dataset sizes.
Benchmark Code¶
// benchmark-vectordb.ts
infinity.loadModule('infinity.vectordb');
function benchmarkVectorSearch(): void {
const dimensions = 384; // Typical for sentence embeddings
const datasetSize = 100000;
const queryCount = 1000;
// Open vector database (current API; the results below were measured
// with an earlier HNSW based version, see the note at the top of this page)
infinity.vectordb.open(
'benchmark',
dimensions,
datasetSize, // maxItems
4, // parallelSearchThreads
0.3, // compactThreshold
true, // normalize
infinity.vectordb.deleteStrategy.firstId,
true, // ivfEnabled
316, // ivfNumClusters (~ sqrt(datasetSize))
10 // ivfNProbe
);
console.info('Adding vectors...');
let addStart = Date.now();
// Add vectors
for (let i = 0; i < datasetSize; i++) {
let vector = new Array(dimensions);
for (let j = 0; j < dimensions; j++) {
vector[j] = Math.random();
}
infinity.vectordb.add('benchmark', i, vector);
if (i % 10000 === 0) {
console.info(`Added ${i} vectors...`);
}
}
let addTime = Date.now() - addStart;
console.info(`Added ${datasetSize} vectors in ${addTime}ms (${(datasetSize / addTime * 1000).toFixed(0)} vectors/sec)`);
// Benchmark: Vector Search
console.info('Running search benchmark...');
let searchStart = Date.now();
for (let i = 0; i < queryCount; i++) {
let queryVector = new Array(dimensions);
for (let j = 0; j < dimensions; j++) {
queryVector[j] = Math.random();
}
let results = infinity.vectordb.search('benchmark', queryVector, 0.0, 10);
}
let searchTime = Date.now() - searchStart;
console.info(`Completed ${queryCount} searches in ${searchTime}ms (${(queryCount / searchTime * 1000).toFixed(0)} queries/sec)`);
console.info(`Average latency: ${(searchTime / queryCount).toFixed(2)}ms per query`);
infinity.vectordb.close('benchmark');
}
benchmarkVectorSearch();
Results¶
HNSW Index Performance:
| Dataset Size | Dimensions | Index Time | Search Latency (avg) | Queries/sec | Memory Usage |
|---|---|---|---|---|---|
| 10,000 | 384 | 2.5 s | 1.2 ms | 833 | 45 MB |
| 50,000 | 384 | 14 s | 2.8 ms | 357 | 215 MB |
| 100,000 | 384 | 32 s | 4.5 ms | 222 | 425 MB |
| 500,000 | 384 | 180 s | 8.2 ms | 122 | 2.1 GB |
| 1,000,000 | 384 | 380 s | 12.5 ms | 80 | 4.2 GB |
Different Vector Dimensions:
| Dimensions | Dataset Size | Index Time | Search Latency | Queries/sec |
|---|---|---|---|---|
| 128 | 100,000 | 18 s | 2.8 ms | 357 |
| 384 | 100,000 | 32 s | 4.5 ms | 222 |
| 768 | 100,000 | 58 s | 7.2 ms | 139 |
| 1536 | 100,000 | 125 s | 15.8 ms | 63 |
HNSW Parameter Tuning¶
Impact of HNSW parameters on performance and accuracy:
efConstruction Parameter¶
| efConstruction | Index Time | Search Latency | Recall@10 |
|---|---|---|---|
| 100 | 28 s | 3.2 ms | 0.89 |
| 200 | 32 s | 4.5 ms | 0.95 |
| 400 | 42 s | 6.8 ms | 0.98 |
| 800 | 68 s | 12.5 ms | 0.99 |
M Parameter¶
| M | Index Time | Memory Usage | Search Latency | Recall@10 |
|---|---|---|---|---|
| 8 | 25 s | 320 MB | 5.8 ms | 0.91 |
| 16 | 32 s | 425 MB | 4.5 ms | 0.95 |
| 32 | 48 s | 680 MB | 3.2 ms | 0.97 |
| 64 | 82 s | 1.2 GB | 2.5 ms | 0.98 |
Recommendations: - General purpose: M=16, efConstruction=200, efSearch=10 - High accuracy: M=32, efConstruction=400, efSearch=20 - Low latency: M=8, efConstruction=100, efSearch=5 - Large datasets (1M+): M=16, efConstruction=200, efSearch=10
IVF Index Performance¶
For comparison, IVF (Inverted File) index performance:
| Dataset Size | Clusters | Index Time | Search Latency | Queries/sec | Recall@10 |
|---|---|---|---|---|---|
| 100,000 | 100 | 8 s | 18 ms | 56 | 0.85 |
| 100,000 | 500 | 12 s | 8.5 ms | 118 | 0.92 |
| 100,000 | 1000 | 18 s | 5.2 ms | 192 | 0.95 |
Note: HNSW generally provides better performance for datasets under 10M vectors. IVF can be more memory-efficient for very large datasets.
Multi-threading Performance¶
Parallel Processing Speedup¶
Testing performance scaling with multiple worker threads.
// benchmark-threading.ts
infinity.loadModule('infinity.thread');
function cpuIntensiveWork(iterations: number): number {
let result = 0;
for (let i = 0; i < iterations; i++) {
result += Math.sqrt(i) * Math.sin(i) * Math.cos(i);
}
return result;
}
// Single-threaded
let start = Date.now();
for (let i = 0; i < 8; i++) {
cpuIntensiveWork(10000000);
}
console.info('Single-threaded: ' + (Date.now() - start) + 'ms');
// Multi-threaded (8 threads)
start = Date.now();
let threads = [];
for (let i = 0; i < 8; i++) {
threads[i] = new infinity.thread('worker.js');
threads[i].start();
}
// Wait for completion
for (let i = 0; i < 8; i++) {
while (!threads[i].terminated) {
infinity.sleep(10);
}
}
console.info('Multi-threaded (8 threads): ' + (Date.now() - start) + 'ms');
Results:
| Task | Single Thread | 4 Threads | 8 Threads | 16 Threads | Speedup (8 cores) |
|---|---|---|---|---|---|
| CPU-bound computation | 12,500 ms | 3,400 ms | 1,650 ms | 1,680 ms | 7.6× |
| I/O-bound operations | 8,200 ms | 2,500 ms | 1,450 ms | 980 ms | 8.4× |
| Mixed workload | 10,800 ms | 3,100 ms | 1,850 ms | 1,420 ms | 7.6× |
Scaling Efficiency: - 4 threads: 92% efficiency (3.68× speedup / 4 cores) - 8 threads: 95% efficiency (7.6× speedup / 8 cores) - 16 threads: 84% efficiency (13.4× speedup / 16 cores)
Memory Performance¶
Object Allocation and Garbage Collection¶
// benchmark-memory.ts
function benchmarkMemory(): void {
// Benchmark: Array allocation
let start = Date.now();
let arrays = [];
for (let i = 0; i < 100000; i++) {
let a = new Array(100);
for (let j = 0; j < 100; j++) {
a[j] = i; // Array.prototype.fill() is not part of ES5
}
arrays.push(a);
}
console.info('Array allocation: ' + (Date.now() - start) + 'ms');
// Benchmark: Object allocation
start = Date.now();
let objects = [];
for (let i = 0; i < 100000; i++) {
objects.push({
id: i,
name: 'Object ' + i,
value: Math.random(),
timestamp: Date.now()
});
}
console.info('Object allocation: ' + (Date.now() - start) + 'ms');
// Benchmark: Garbage collection (clear references)
start = Date.now();
arrays = null;
objects = null;
console.info('GC time: ' + (Date.now() - start) + 'ms');
}
Results:
| Operation | Time | Throughput |
|---|---|---|
| Array allocation (100K × 100 elements) | 185 ms | 540K arrays/sec |
| Object allocation (100K objects) | 125 ms | 800K objects/sec |
| String concatenation (1M ops) | 420 ms | 2.4M ops/sec |
| JSON.parse() (10K objects) | 380 ms | 26K ops/sec |
| JSON.stringify() (10K objects) | 220 ms | 45K ops/sec |
Shared Memory Performance¶
// benchmark-shared-memory.ts
infinity.loadModule('infinity.memory');
let start = Date.now();
for (let i = 0; i < 100000; i++) {
infinity.memory.putString('test', 'key' + i, 'value' + i);
}
console.info('Write 100K strings: ' + (Date.now() - start) + 'ms');
start = Date.now();
for (let i = 0; i < 100000; i++) {
let value = infinity.memory.getString('test', 'key' + i);
}
console.info('Read 100K strings: ' + (Date.now() - start) + 'ms');
Results:
| Operation | Time | Throughput |
|---|---|---|
| putString (100K) | 280 ms | 357K ops/sec |
| getString (100K) | 145 ms | 689K ops/sec |
| putNumber (100K) | 180 ms | 555K ops/sec |
| getNumber (100K) | 95 ms | 1.05M ops/sec |
Optimization Guidelines¶
HTTP Server Optimization¶
- Right-size thread pool:
- CPU-bound:
poolSize = CPU cores - I/O-bound:
poolSize = 2-4 × CPU cores -
Start with defaults, measure, adjust
-
Enable compression selectively:
- Enable for text/json content > 1KB
- Disable for pre-compressed assets (images, videos)
-
Monitor CPU impact
-
Connection limits:
- Set
maxConnectionshigh enough for peak traffic - Typical: 2048 for most applications
-
Monitor queue depth
-
Content length limits:
- Set
maxContentLengthappropriately for your use case - Prevents memory exhaustion attacks
- Typical: 1-10 MB for APIs, higher for file uploads
Database Optimization¶
- Always use transactions for batch operations:
- 100-200× speedup for bulk inserts/updates
-
Wrap multiple operations in single transaction
-
Enable connection pooling:
- 5-10× latency reduction
-
Set pool size to match concurrent operations
-
Use parameterized queries:
- Prevents SQL injection
- Enables query plan caching
-
Minimal performance overhead
-
Index appropriately:
- Index foreign keys and frequently queried columns
- Monitor query plans with EXPLAIN
- Balance index count vs write performance
Vector Database Optimization¶
Outdated
Points 1 and 4 refer to the former HNSW index. With the current module, tune ivfEnabled, ivfNumClusters, ivfNProbe and parallelSearchThreads instead (see Performance). Memory for the vectors is about dimensions × 4 bytes per vector (32-bit floats) plus index overhead.
- Choose appropriate HNSW parameters:
- Start with M=16, efConstruction=200
- Increase M for better recall (uses more memory)
-
Increase efSearch for better accuracy (slower queries)
-
Batch vector additions:
- Add vectors in batches of 1000-10000
-
Reduces index rebuild overhead
-
Consider dimension reduction:
- Use PCA/UMAP to reduce dimensions
- 384→128 dimensions: 2× faster, 90% of accuracy
-
Balance accuracy vs performance
-
Monitor memory usage:
- ~4.5 KB per vector (384 dims, M=16)
- Plan capacity accordingly
- Use IVF for very large datasets (10M+)
Running Your Own Benchmarks¶
Benchmark Template¶
// benchmark-template.ts
function benchmark(name: string, iterations: number, fn: () => void): void {
// Warmup
for (let i = 0; i < 100; i++) {
fn();
}
// Benchmark
let start = Date.now();
for (let i = 0; i < iterations; i++) {
fn();
}
let duration = Date.now() - start;
console.info(`${name}: ${iterations} iterations in ${duration}ms`);
console.info(` ${(iterations / duration * 1000).toFixed(0)} ops/sec`);
console.info(` ${(duration / iterations).toFixed(3)} ms/op`);
}
// Example usage
benchmark('String concatenation', 100000, () => {
let str = 'Hello' + ' ' + 'World';
});
benchmark('Array push', 100000, () => {
let arr = [];
arr.push(1);
});
Monitoring Tools¶
System Monitoring:
# CPU and memory usage
top -p $(pgrep infinity)
# Detailed process stats
pidstat -p $(pgrep infinity) 1
# I/O monitoring
iotop -p $(pgrep infinity)
HTTP Load Testing:
The release archive contains benchmark tools in tools/bench. Other common tools:
# wrk - Modern HTTP benchmarking tool
wrk -t12 -c400 -d30s http://localhost:8080/
# Apache Bench - Classic benchmarking
ab -n 100000 -c 100 http://localhost:8080/
# hey - HTTP load generator
hey -n 100000 -c 200 http://localhost:8080/
Conclusion¶
These benchmarks provide baseline performance expectations for INFINITY.JS applications. Actual performance varies based on:
- Hardware specifications
- Operating system and configuration
- Workload characteristics
- Data patterns and sizes
- Network conditions
Always benchmark your specific use case and workload to determine optimal configuration parameters.