Pre-configured engine settings for common use cases.
Engine presets provide convenient configurations that combine worker execution, WASM acceleration, and streaming strategies for optimal performance in different scenarios.
Stability Considerations:
stable - Uses only standard JavaScript APIs, works everywhere, supports WHATWG Encoding Standard encodingsresponsive, fast, responsiveFast - Use stable Web Workers and/or WebAssembly APIs but may require bundler configurationmemoryEfficient, balanced - Use Transferable Streams API which is still evolving and may change (both have automatic stable fallback)All presets are functions that optionally accept configuration options like workerPool, workerURL, arrayBufferThreshold, backpressureCheckInterval, queuingStrategy, and onFallback.
Each preset is optimized for specific performance characteristics:
Basic usage:
engine: EnginePresets.balanced()
With WorkerPool:
import { ReusableWorkerPool } from 'web-csv-toolbox';
const pool = new ReusableWorkerPool({ maxWorkers: 4 });
engine: EnginePresets.balanced({ workerPool: pool })
| Preset | Optimization Target | Worker | WASM | Strategy | Stability |
|---|---|---|---|---|---|
stable |
Stability | ❌ | ❌ | - | ⭐ Most Stable |
responsive |
UI responsiveness | ✅ | ❌ | message-streaming | ✅ Stable |
memoryEfficient |
Memory efficiency | ✅ | ❌ | stream-transfer | ⚠️ Experimental |
fast |
Parse speed | ❌ | ✅ | - | ✅ Stable |
responsiveFast |
UI responsiveness + parse speed | ✅ | ✅ | message-streaming | ✅ Stable |
balanced |
Balanced (general-purpose) | ✅ | ❌ | stream-transfer | ⚠️ Experimental |
EnginePresets.stable(){
worker: false,
wasm: false
}
Description: Most stable configuration using only standard JavaScript APIs.
Optimization target: Stability
Performance characteristics:
Trade-offs:
Use when:
Example:
import { parseString, EnginePresets } from 'web-csv-toolbox';
for await (const record of parseString(csv, {
engine: EnginePresets.stable()
})) {
console.log(record);
}
EnginePresets.responsive(){
worker: true,
wasm: false,
workerStrategy: "message-streaming"
}
Description: UI responsiveness optimized configuration.
Optimization target: UI responsiveness (non-blocking)
Performance characteristics:
Trade-offs:
Use when:
Example:
import { parseString, EnginePresets } from 'web-csv-toolbox';
for await (const record of parseString(csv, {
engine: EnginePresets.responsive()
})) {
console.log(record);
// UI stays responsive!
}
EnginePresets.memoryEfficient(){
worker: true,
wasm: false,
workerStrategy: "stream-transfer"
}
Description: Memory efficiency optimized configuration.
Optimization target: Memory efficiency
Performance characteristics:
Trade-offs:
Use when:
Example:
import { parse, EnginePresets } from 'web-csv-toolbox';
const response = await fetch('huge-data.csv');
for await (const record of parse(response, {
engine: EnginePresets.memoryEfficient()
})) {
console.log(record);
// Memory: O(1) per record
}
EnginePresets.fast(){
worker: false,
wasm: true
}
Description: Parse speed optimized configuration.
Optimization target: Parse speed (execution time)
Performance characteristics:
Trade-offs:
") onlyUse when:
Limitations:
") as quotation characterloadWASM() before useExample:
import { parseString, EnginePresets, loadWASM } from 'web-csv-toolbox';
await loadWASM();
for await (const record of parseString(csv, {
engine: EnginePresets.fast()
})) {
console.log(record);
}
EnginePresets.responsiveFast(){
worker: true,
wasm: true,
workerStrategy: "message-streaming"
}
Description: UI responsiveness + parse speed optimized configuration.
Optimization target: UI responsiveness + parse speed
Performance characteristics:
Trade-offs:
") onlyUse when:
Example:
import { parseString, EnginePresets, loadWASM } from 'web-csv-toolbox';
await loadWASM();
for await (const record of parseString(csv, {
engine: EnginePresets.responsiveFast()
})) {
console.log(record);
// Fast + non-blocking!
}
EnginePresets.balanced(){
worker: true,
wasm: false,
workerStrategy: "stream-transfer"
}
Description: Balanced configuration for general-purpose CSV processing.
Optimization target: Balanced (UI responsiveness + memory efficiency + broad compatibility)
Performance characteristics:
Trade-offs:
Use when:
Example:
import { parseStringStream, EnginePresets, ReusableWorkerPool } from 'web-csv-toolbox';
const pool = new ReusableWorkerPool({ maxWorkers: 4 });
app.post('/validate-csv', async (c) => {
if (pool.isFull()) {
return c.json({ error: 'Service busy' }, 503);
}
const csvStream = c.req.raw.body?.pipeThrough(new TextDecoderStream());
for await (const record of parseStringStream(csvStream, {
engine: EnginePresets.balanced({ workerPool: pool })
})) {
// Process securely...
}
});
Example with Custom Blob Reading Threshold:
import { parseBlob, EnginePresets } from 'web-csv-toolbox';
// Optimize for small files: always use arrayBuffer up to 512KB
const config = EnginePresets.balanced({
arrayBufferThreshold: 512 * 1024 // 512KB
});
for await (const record of parseBlob(file, {
engine: config
})) {
console.log(record);
}
Example with Advanced Performance Tuning (Experimental):
import { parseBlob, EnginePresets } from 'web-csv-toolbox';
// Configuration tuned for potential high-throughput scenarios
const config = EnginePresets.balanced({
arrayBufferThreshold: 2 * 1024 * 1024, // 2MB
backpressureCheckInterval: {
lexer: 200, // Check every 200 tokens (less frequent checks)
assembler: 20 // Check every 20 records (less frequent checks)
},
queuingStrategy: {
// Tune entire pipeline with larger buffers
lexerWritable: new CountQueuingStrategy({ highWaterMark: 200 }),
lexerReadable: new CountQueuingStrategy({ highWaterMark: 100 }),
assemblerWritable: new CountQueuingStrategy({ highWaterMark: 100 }),
assemblerReadable: new CountQueuingStrategy({ highWaterMark: 50 })
}
});
for await (const record of parseBlob(file, {
engine: config
})) {
console.log(record);
}
Choose the preset that matches your primary optimization goal:
Stability: stable ⭐
UI Responsiveness: responsive or balanced
responsive: ✅ Stable, WHATWG Encoding Standard encodingsbalanced: ⚠️ Experimental (with stable fallback), memory efficientParse Speed: fast or responsiveFast
fast: ✅ Fastest parse time, blocks main thread, UTF-8 onlyresponsiveFast: ✅ Non-blocking + fast parsing, UTF-8 onlyMemory Efficiency: memoryEfficient or balanced
memoryEfficient: ⚠️ Experimental, zero-copy streamsbalanced: ⚠️ Experimental (with stable fallback), general-purposeGeneral-purpose CSV processing: balanced
Maximum stability required: stable
Browser with interactive UI: responsive or balanced
responsive: ✅ Stable, WHATWG Encoding Standard encodingsbalanced: ⚠️ Experimental with fallback, memory efficientServer-side parsing: stable or fast
stable: ⭐ Most stable, WHATWG Encoding Standard encodingsfast: ✅ Faster parse speed, UTF-8 onlyUTF-8 files only: fast or responsiveFast
fast: ✅ Fastest parse time, blocks main threadresponsiveFast: ✅ Non-blocking + fast parsingStreaming large files: memoryEfficient or balanced
Browser (UI-critical): responsive or balanced
responsive: ✅ Stablebalanced: ⚠️ Experimental with stable fallbackBrowser (UTF-8 only): responsiveFast
Server-side: stable or fast
stable: ⭐ Most stable, WHATWG Encoding Standard encodingsfast: ✅ Faster parsing, UTF-8 onlySafari required: responsive or balanced
responsive: ✅ Stable, message-streamingbalanced: ⚠️ Experimental with automatic fallbackChrome/Firefox/Edge only: memoryEfficient
Note: Choose execution strategy based on your requirements (stability, blocking vs non-blocking, parse speed, memory efficiency, encoding support) rather than file size alone. Benchmark your specific use case to determine the best approach.
For advanced configuration options beyond presets, refer to the EngineConfig type documentation in your IDE or the API Reference.