fortify2-js
Version:
MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.
94 lines (90 loc) • 3.77 kB
JavaScript
;
var safeSerializer = require('../../serializer/safe-serializer.js');
var fortifiedLogger = require('../fortified-logger.js');
/**
* Execution Router - Modular component for routing execution to appropriate engines
* Part of the minimal modular architecture
*/
class ExecutionRouter {
constructor(options, ultraFastEngine, ultraFastCache, performanceMonitor, functionSignature) {
this.ultraFastEngine = ultraFastEngine;
this.ultraFastCache = ultraFastCache;
this.performanceMonitor = performanceMonitor;
this.functionSignature = functionSignature;
}
/**
* Execute with ultra-fast engine and all optimizations
*/
async executeWithUltraFastEngine(originalFunction, args, options, functionId, globalMetrics) {
performance.now();
// Check ultra-fast cache first
if (options.memoize || options.smartCaching) {
const cacheKey = this.generateOptimizedCacheKey(args);
const cached = this.ultraFastCache.get(cacheKey);
if (cached !== null) {
globalMetrics.totalCacheHits++;
return cached;
}
globalMetrics.totalCacheMisses++;
}
// For simple operations, bypass engine overhead
const fnString = originalFunction.toString();
const isSimpleOperation = fnString.length < 100 &&
!fnString.includes("await") &&
!fnString.includes("Promise");
let result;
if (isSimpleOperation && !options.enableJIT) {
// Ultra-fast path: Direct execution for simple operations
result = originalFunction(...args);
}
else {
// Optimized path: Use ultra-fast engine for complex operations
result = this.ultraFastEngine.executeLightning(originalFunction, args, this.functionSignature);
}
// Resolve promise if needed
const resolvedResult = result instanceof Promise ? await result : result;
// Cache result with prediction
if (options.memoize || options.smartCaching) {
const cacheKey = this.generateOptimizedCacheKey(args);
this.ultraFastCache.set(cacheKey, resolvedResult, options.cacheTTL);
}
return resolvedResult;
}
/**
* Ultra-fast execution: Bypass all overhead for maximum performance
*/
async executeUltraFast(originalFunction, args, options, globalMetrics) {
// Ultra-fast: Direct execution with minimal cache check
if (options.memoize) {
const cacheKey = safeSerializer.generateSafeCacheKey(args, "ultrafast");
const cached = this.performanceMonitor.getCachedResult(cacheKey);
if (cached !== null) {
globalMetrics.totalCacheHits++;
return cached;
}
globalMetrics.totalCacheMisses++;
// Execute function directly
const result = await originalFunction(...args);
// Simple cache store
this.performanceMonitor.cacheResult(cacheKey, result, options.cacheTTL);
return result;
}
// Ultra-fast: Direct execution without any overhead
return await originalFunction(...args);
}
/**
* Generate optimized cache key
*/
generateOptimizedCacheKey(args) {
return `${this.functionSignature}:${safeSerializer.generateSafeCacheKey(args, "optimized")}`;
}
/**
* Cleanup resources
*/
destroy() {
// Cleanup handled by individual components
fortifiedLogger.fortifiedLogger.debug("EXECUTION_ROUTER", "Execution router destroyed");
}
}
exports.ExecutionRouter = ExecutionRouter;
//# sourceMappingURL=execution-router.js.map