nodeboost
v1.9.0
Published
A JIT Compilation Middleware for Node.js to Improve Performance
Downloads
3
Maintainers
Readme
NodeBoost: JIT Compilation Middleware for Node.js
NodeBoost is a Just-In-Time (JIT) Compilation Middleware for Node.js that aims to improve the performance of critical sections of your Node.js applications.
Features
- Selective JIT compilation of critical functions.
- Runtime profiling and tracking of function execution times.
- Debug mode for detailed logging during function execution.
- Customizable compilation options to fit your application's needs.
Installation
To install NodeBoost in your Node.js project, use NPM:
npm install nodeboost
Usage
Marking a Function for JIT Compilation
const express = require('express');
const { markForJIT, jitMiddleware, profileFunctionExecution, getProfileData, setDebugMode, isDebugMode, preWarmCompiledFunctions } = require('nodeboost');
const app = express();
function expensiveCalculation(input) {
let result = 0;
for (let i = 1; i <= input; i++) {
result += i;
}
return result;
}
markForJIT(expensiveCalculation, { strategy: 'aggressive', sampleArgs: [1000000] });
app.use(jitMiddleware);
app.get('/', (req, res) => {
const startTime = Date.now();
const result = expensiveCalculation(1000000);
const executionTime = Date.now() - startTime;
profileFunctionExecution(expensiveCalculation, [1000000], result, executionTime);
if (isDebugMode()) {
console.log(`Debug Mode: Executed function ${expensiveCalculation.name} in ${executionTime}ms`);
}
res.send(`Result: ${result} (Execution Time: ${executionTime}ms)`);
});
app.get('/profile', (req, res) => {
const profileData = getProfileData();
res.json(profileData);
});
app.get('/toggle-debug', (req, res) => {
const debug = req.query.debug === 'true';
setDebugMode(debug);
res.send(`Debug Mode: ${debug}`);
});
app.get('/pre-warm', (req, res) => {
preWarmCompiledFunctions();
res.send(`Pre-warmed JIT-compiled functions.`);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});