Skip to content

Commit

Permalink
Added a tool to measure memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Sep 15, 2023
1 parent bc382ca commit 214bc21
Show file tree
Hide file tree
Showing 11 changed files with 1,895 additions and 205 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ packages/*/package-lock.json
.rpt2_cache_development
.rpt2_cache_production

scripts/fakedom/*
.swc
646 changes: 450 additions & 196 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@
"test:browser:debug-nocompat": "cross-env InfernoCompat=0 npm run --prefix fixtures/browser debug:swc",
"test:browser:sauce": "npm run --prefix fixtures/browser test",
"test:react": "npm run --prefix fixtures/react test -- --forceExit",
"test:package": "node fixtures/packaging/build-all.js"
"test:package": "node fixtures/packaging/build-all.js",
"test:memory": "node --expose-gc scripts/fakedom/uibench-reactlike/start.js"
},
"devDependencies": {
"@babel/core": "^7.22.17",
"@babel/core": "^7.22.19",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-transform-modules-commonjs": "^7.22.15",
"@babel/preset-env": "7.22.15",
"@babel/preset-typescript": "^7.22.15",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@types/jest": "^29.5.4",
"@types/jsdom": "^21.1.2",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"babel-plugin-inferno": "6.7.0",
"cli-table": "^0.3.11",
"concat-stream-es6": "0.0.1",
Expand All @@ -80,15 +82,15 @@
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^39.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"filesize": "^10.0.12",
"fs-extra": "^11.1.1",
"gzip-size": "^7.0.0",
"history": "^5.3.0",
"jest-environment-jsdom": "^29.6.4",
"jest-jasmine2": "^29.6.4",
"jest-environment-jsdom": "^29.7.0",
"jest-jasmine2": "^29.7.0",
"jest-silent-reporter": "^0.5.0",
"jsdom": "^22.1.0",
"lerna": "^6",
Expand All @@ -106,7 +108,7 @@
"rollup-plugin-replace": "^2.2.0",
"swc": "^1.0.11",
"swc-loader": "^0.2.3",
"swc-plugin-inferno": "^0.0.6",
"swc-plugin-inferno": "^0.0.7",
"ts-jest": "^29.1.1",
"ts-plugin-inferno": "^6.0.2",
"typescript": "^5.2.2"
Expand Down
116 changes: 116 additions & 0 deletions scripts/fakedom/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import {rollup} from "rollup";
import { existsSync, readdirSync, statSync } from "fs";
import commonjsPlugin from "rollup-plugin-commonjs";
import nodeResolvePlugin from "rollup-plugin-node-resolve";
import { dirname, join, resolve } from "path";
import replace from "rollup-plugin-replace";
import terser from '@rollup/plugin-terser';
import alias from "@rollup/plugin-alias";
import { fileURLToPath } from "url";
import babel from "@rollup/plugin-babel";
import jsonPlugin from "@rollup/plugin-json"

const isProduction = process.env.NODE_ENV === 'production';

const __dirname = dirname(fileURLToPath(import.meta.url));
const benchmarks = readdirSync(__dirname).filter(file => statSync(join(__dirname, file)).isDirectory());
const resolvePkg = pkg => resolve(__dirname, '../../packages', pkg, 'dist', 'index.esnext.js');


console.log(resolvePkg('inferno'));

// see below for details on the options
const plugins = [
replace({
'process.env.NODE_ENV': '"production"',
sourcemap: false
}),
nodeResolvePlugin({
preferBuiltins: false
}),
babel({
exclude: 'node_modules/**',
sourceMaps: false,
babelrc: false,
plugins: [
['babel-plugin-inferno', {imports: true, defineAllArguments: true}],
]
}),
commonjsPlugin({
sourceMap: false
}),
jsonPlugin(),
alias({
resolve: ['.js'],
entries: [
{find: 'inferno', replacement: resolvePkg('inferno')},
{find: 'inferno-animation', replacement: resolvePkg('inferno-animation')},
{find: 'inferno-compat', replacement: resolvePkg('inferno-compat')},
{find: 'inferno-create-element', replacement: resolvePkg('inferno-create-element')},
{find: 'inferno-hydrate', replacement: resolvePkg('inferno-hydrate')},
{find: 'inferno-extras', replacement: resolvePkg('inferno-extras')},
{find: 'inferno-hyperscript', replacement: resolvePkg('inferno-hyperscript')},
{find: 'inferno-mobx', replacement: resolvePkg('inferno-mobx')},
{find: 'inferno-redux', replacement: resolvePkg('inferno-redux')},
{find: 'inferno-router', replacement: resolvePkg('inferno-router')},
{find: 'inferno-server', replacement: resolvePkg('inferno-server')},
{find: 'inferno-shared', replacement: resolvePkg('inferno-shared')},
{find: 'inferno-test-utils', replacement: resolvePkg('inferno-test-utils')},
{find: 'inferno-vnode-flags', replacement: resolvePkg('inferno-vnode-flags')},
{find: 'inferno-clone-vnode', replacement: resolvePkg('inferno-clone-vnode')},
{find: 'mobx', replacement: join(__dirname, '../../node_modules/mobx/dist/mobx.esm.js')}
]
})
];

if (isProduction) {
plugins.push(
terser({
compress: {
ecma: 5,
inline: true,
if_return: false,
reduce_funcs: false,
passes: 5,
comparisons: false,
},
ie8: false,
mangle: {
toplevel: true
},
parse: {
html5_comments: false,
shebang: false
},
toplevel: false,
warnings: false
})
);
}

for (const dir of benchmarks) {
const benchmarkPath = join(__dirname, dir);
const appJsPath = resolve(benchmarkPath, 'app.js')

// Don't build examples that don't have app.js
if (!existsSync(appJsPath)) continue;

const inputOptions = {
input: appJsPath,
external: ['os', 'fs', 'path', 'vm', 'url'],
plugins: plugins
};

const start = new Date();

console.log(`Build started -- ${start}`);

rollup(inputOptions).then(function (opts) {
return opts.write({
format: 'esm',
file: join(benchmarkPath, 'dist', 'bundle.js'),
sourcemap: false,
name: 'inferno'
});
});
}
12 changes: 12 additions & 0 deletions scripts/fakedom/libs/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {JSDOM} from 'jsdom';
const dom = new JSDOM(`<!DOCTYPE html><html><body><div id="app"></div></body></html>`);

const rafMock = Promise.resolve().then.bind(Promise.resolve());

global.window = dom.window;
global.document = dom.window.document;
global.Node = dom.window.Node;
global.window.requestAnimationFrame = rafMock
global.requestAnimationFrame = rafMock;

export const container = dom.window.document.querySelector("#app");
Loading

0 comments on commit 214bc21

Please sign in to comment.