Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9db6211
added tree-shaking test example
bennobuilder Jul 28, 2021
3a6c84b
tried to tree shake collection
bennobuilder Jul 30, 2021
e805e05
fixed typos
bennobuilder Jul 30, 2021
98afcac
optimized treeshaking collection
bennobuilder Jul 31, 2021
0afa034
readded internal because of import order error
bennobuilder Aug 1, 2021
a1da58f
added release manual command
bennobuilder Aug 1, 2021
35d2b88
fixed tests
bennobuilder Aug 1, 2021
7b728a2
made computed state tree shakable
bennobuilder Aug 1, 2021
90bce94
removed 'type()' method
bennobuilder Aug 1, 2021
29294c1
readded cjs support (https://blog.logrocket.com/publishing-node-modu…
bennobuilder Aug 1, 2021
70e80e9
fixed typo
bennobuilder Aug 2, 2021
ff26d37
updated ts configs
bennobuilder Aug 3, 2021
32f4bdb
fixed typo
bennobuilder Aug 3, 2021
44f8415
tested tree shakability at a react project
bennobuilder Aug 3, 2021
458d665
tree shaking logger in prod
bennobuilder Aug 4, 2021
fafdfa5
created treeshaking example
bennobuilder Aug 4, 2021
fcc6b76
extract metafile from bundle (benchmark test)
bennobuilder Aug 5, 2021
123b45e
fixed typo
bennobuilder Aug 7, 2021
809efa4
implemented yargs
bennobuilder Aug 7, 2021
21a4deb
fixed typo
bennobuilder Aug 8, 2021
3a01dc2
fixed agile bench
bennobuilder Aug 8, 2021
59b4c8b
updated benchmark to esm
bennobuilder Aug 9, 2021
653f8e7
fixed tests
bennobuilder Aug 10, 2021
3c24b00
removed is dev variable because if not directly checking if the env i…
bennobuilder Aug 10, 2021
f7cfe79
fixed typos
bennobuilder Aug 11, 2021
9de3ba1
fixed typos
bennobuilder Aug 12, 2021
86cf54a
fixed typo
bennobuilder Aug 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ To find out more about contributing, check out the [CONTRIBUTING.md](https://git
<img src="https://codeclimate.com/github/agile-ts/agile/badges/gpa.svg" alt="Maintainability"/>
</a>

### ♥️ Contributors

<a href="https://github.com/agile-ts/agile/graphs/contributors">
<img src="https://contrib.rocks/image?repo=agile-ts/agile" />
</a>

[Become a contributor](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md)


<br />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import ReactDom from 'react-dom';
import { createCollection, LogCodeManager } from '@agile-ts/core';
import { useAgile, useValue } from '@agile-ts/react';
import { createCollection, shared } from '@agile-ts/core';
import reactIntegration, { useAgile, useValue } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

LogCodeManager.getLogger().isActive = false;
assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

export default function (target: HTMLElement, fieldsCount: number) {
const FIELDS = createCollection({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { createState, LogCodeManager, State } from '@agile-ts/core';
import { useAgile } from '@agile-ts/react';
import { createState, shared, State } from '@agile-ts/core';
import reactIntegration, { useAgile } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

LogCodeManager.getLogger().isActive = false;
assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

export default function (target: HTMLElement, fieldsCount: number) {
const FIELDS = createState(
Expand Down
8 changes: 5 additions & 3 deletions benchmark/benchmarks/react/1000fields/bench/agilets/state.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import ReactDom from 'react-dom';
import { createState, LogCodeManager } from '@agile-ts/core';
import { useAgile } from '@agile-ts/react';
import { createState, shared } from '@agile-ts/core';
import reactIntegration, { useAgile } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

LogCodeManager.getLogger().isActive = false;
assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

export default function (target: HTMLElement, fieldsCount: number) {
const FIELDS = createState(
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/react/1000fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
endBenchmarkLog,
getCycleResult,
startBenchmarkLog,
} from '../../../benchmarkManager';
} from '../../benchmarkManager';

// Files to run the Benchmark on
import agileCollection from './bench/agilets/collection';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import ReactDom from 'react-dom';
import { createComputed, createState, LogCodeManager } from '@agile-ts/core';
import { useAgile } from '@agile-ts/react';
import { createComputed, createState, shared } from '@agile-ts/core';
import reactIntegration, { useAgile } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

LogCodeManager.getLogger().isActive = false;
const COUNT = createState(0);
const COMPUTED_COUNT = createComputed(() => {
return COUNT.value * 5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import ReactDom from 'react-dom';
import { createComputed, createState, LogCodeManager } from '@agile-ts/core';
import { useAgile } from '@agile-ts/react';
import { createComputed, createState, shared } from '@agile-ts/core';
import reactIntegration, { useAgile } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

LogCodeManager.getLogger().isActive = false;
const COUNT = createState(0);
const COMPUTED_COUNT = createComputed(
() => {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/react/computed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
endBenchmarkLog,
getCycleResult,
startBenchmarkLog,
} from '../../../benchmarkManager';
} from '../../benchmarkManager';

// Files to run the Benchmark on
import agileAutoTracking from './bench/agilets/autoTracking';
Expand Down
11 changes: 7 additions & 4 deletions benchmark/benchmarks/react/counter/bench/agilets.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React from 'react';
import ReactDom from 'react-dom';
import { createState, LogCodeManager } from '@agile-ts/core';
import { useAgile } from '@agile-ts/react';
import { createState, shared } from '@agile-ts/core';
import reactIntegration, { useAgile } from '@agile-ts/react';
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';

assignSharedAgileLoggerConfig({ active: false });
shared.integrate(reactIntegration);

LogCodeManager.getLogger().isActive = false;
const COUNT = createState(0);

const App = () => {
const count = useAgile(COUNT, undefined);
const count = useAgile(COUNT);
return <h1 onClick={() => COUNT.set((state) => state + 1)}>{count}</h1>;
};

Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/react/counter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
endBenchmarkLog,
getCycleResult,
startBenchmarkLog,
} from '../../../benchmarkManager';
} from '../../benchmarkManager';

// Files to run the Benchmark on
import agilets from './bench/agilets';
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/typescript/defineConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
endBenchmarkLog,
getCycleResult,
startBenchmarkLog,
} from '../../../benchmarkManager';
} from '../../benchmarkManager';

// Files to run the Benchmark on
import * as referencer from './bench/referencer';
Expand Down
6 changes: 4 additions & 2 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"homepage": "https://agile-ts.org/",
"description": "Benchmark Tests",
"scripts": {
"test": "node -r esbuild-register run.ts",
"test": "node -r esbuild-register runtime/run.ts",
"test:counter": "yarn test ./benchmarks/react/counter",
"test:1000fields": "yarn test ./benchmarks/react/1000fields",
"test:computed": "yarn test ./benchmarks/react/computed",
Expand Down Expand Up @@ -45,13 +45,15 @@
"redux": "^4.1.0",
"typescript": "^4.3.5",
"valtio": "^1.0.6",
"yargs": "^17.1.0",
"zustand": "^3.5.5"
},
"devDependencies": {
"@types/benchmark": "^2.1.0",
"@types/node": "^16.0.0",
"@types/react": "^17.0.13",
"@types/react-dom": "^17.0.8"
"@types/react-dom": "^17.0.8",
"@types/yargs": "^17.0.2"
},
"bugs": {
"url": "https://github.com/agile-ts/agile/issues"
Expand Down
79 changes: 56 additions & 23 deletions benchmark/run.ts → benchmark/runtime/benchmarkTypes.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import dotenv from 'dotenv';
import chalk from 'chalk';
import esbuild from 'esbuild';
import playwright from 'playwright';
import chalk from 'chalk';

// Loads environment variables from the '.env' file
dotenv.config();

// https://nodejs.org/docs/latest/api/process.html#process_process_argv
// Extract entry (at third parameter) from the executed command
// yarn run ./path/to/entry -> './path/to/entry' is extracted
const entry = process.argv.slice(2)[0];
const dev = process.argv.slice(2)[1] === '--dev' || process.env.DEV === 'true';
if (entry == null) {
throw new Error(
"No valid entry was provided! Valid entry example: 'yarn run ./benchmarks/react/counter'"
);
}
import fs from 'fs';

const startBenchmark = async () => {
console.log(chalk.blue('Starting the benchmark server..\n'));
export const startSpeedBench = async (entry: string, isDev: boolean) => {
console.log(chalk.blue('Starting the speed benchmark server..\n'));

// Bundle Benchmark Test Suite
// and launch the server on which the Test Suite is executed
Expand All @@ -33,9 +19,9 @@ const startBenchmark = async () => {
entryPoints: [entry], // https://esbuild.github.io/api/#entry-points
outfile: './public/bundle.js',
target: 'es2015',
format: 'cjs', // https://esbuild.github.io/api/#format-commonjs
format: 'esm', // https://esbuild.github.io/api/#format-commonjs
platform: 'browser',
minify: !dev, // https://esbuild.github.io/api/#minify
minify: !isDev, // https://esbuild.github.io/api/#minify
bundle: true, // https://esbuild.github.io/api/#bundle
sourcemap: 'external', // https://esbuild.github.io/api/#sourcemap// https://github.com/evanw/esbuild/issues/69
}
Expand All @@ -54,7 +40,7 @@ const startBenchmark = async () => {
const page = await context.newPage();

// Option to open and test the Benchmark Test Suite in the browser manually
if (dev) {
if (isDev) {
console.log(
`${chalk.blue('[i]')} ${chalk.gray(
`Development mode is ${chalk.green(`active`)}`
Expand Down Expand Up @@ -113,5 +99,52 @@ const startBenchmark = async () => {
server.stop();
};

// Execute the Benchmark
startBenchmark();
export const startBundleBench = async (entry: string, isDev: boolean) => {
const bundle = await esbuild.build({
inject: ['./lodash.ts'], // https://esbuild.github.io/api/#inject
entryPoints: [entry], // https://esbuild.github.io/api/#entry-points
outfile: './public/bundle.js',
target: 'es2015',
format: 'esm', // https://esbuild.github.io/api/#format-commonjs
platform: 'browser',
minify: !isDev, // https://esbuild.github.io/api/#minify
bundle: true, // https://esbuild.github.io/api/#bundle
sourcemap: 'external', // https://esbuild.github.io/api/#sourcemap// https://github.com/evanw/esbuild/issues/69
metafile: true, // https://esbuild.github.io/api/#metafile
});

console.log(
`${chalk.blue('[i]')} ${chalk.gray(
`Entry was ${chalk.green(`successfully`)} bundled`
)}`
);

if (isDev) {
console.log(
`${chalk.blue('[i]')} ${chalk.gray(
`Development mode is ${chalk.green(`active`)}`
)}`
);
}

// Extract metafile from bundle (https://esbuild.github.io/api/#metafile)
const metafile = bundle.metafile;

// Calculate bundle file size
let bundleSize = 0;
bundle.outputFiles?.map((file) => {
const stats = fs.statSync(file.path);
const fileSizeInBytes = stats.size;
const fileSizeInKilobytes = fileSizeInBytes / 1024;
bundleSize += fileSizeInKilobytes;
});

console.log(
`${chalk.blue('[i]')} ${chalk.gray(
`Total bundle size of the bundle is ${chalk.blueBright.bold(bundleSize)}`
)}`
);

console.log(metafile);
// TODO analyze metafile
};
51 changes: 51 additions & 0 deletions benchmark/runtime/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import dotenv from 'dotenv';
import { startBundleBench, startSpeedBench } from './benchmarkTypes';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

// Loads environment variables from the '.env' file
dotenv.config();

// hideBind handles the 'process.argv.slice' logic
const argv = yargs(hideBin(process.argv))
.option('_', {
type: 'string',
// default: ['./benchmarks/react/counter'],
description: 'What benchmark to execute',
})
.option('dev', {
type: 'boolean',
default: false,
description:
'Whether to start the benchmark/s in developer mode for better debugging.',
})
.option('type', {
type: 'string',
default: 'speed',
description: 'What type of benchmark to be executed',
}).argv as any;

const entry = argv._[0];
const isDev = argv.dev || process.env.DEV === 'true';
const benchmarkType = argv.type;

if (entry == null) {
throw new Error(
"No valid entry was provided! Valid entry example: 'yarn run ./benchmarks/react/counter'"
);
}

// Benchmarks that can be executed marked with a unique identifier
const benchmarks: {
[key: string]: (entry: string, isDev: boolean) => Promise<void>;
} = {
speed: startSpeedBench,
bundle: startBundleBench,
};

// Execute Benchmark based on the specified Benchmark type
const toExecuteBenchmark = benchmarks[benchmarkType];
if (toExecuteBenchmark != null) toExecuteBenchmark(entry, isDev);
else {
benchmarks['speed'](entry, isDev);
}
Loading