chore: add apps for profiling

This commit is contained in:
shirakaba
2022-12-17 16:53:07 +09:00
parent fe60cfac04
commit 2d0c3ff6a9
40 changed files with 822 additions and 0 deletions

18
apps/old/.eslintrc.json Normal file
View File

@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "node_modules/**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}

42
apps/old/.gitignore vendored Normal file
View File

@@ -0,0 +1,42 @@
# NativeScript
hooks/
node_modules/
platforms/
# NativeScript Template
*.js.map
*.js
!webpack.config.js
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# General
.DS_Store
.AppleDouble
.LSOverride
.idea
.cloud
.project
tmp/
typings/
# misc
npm-debug.log
# app
!*.d.ts
!src/assets/fontawesome.min.css
/report/
.nsbuildinfo
/temp/
/src/tns_modules/
# app uses platform specific scss which can inadvertently get renamed which will cause problems
app/app.scss
package-lock.json

View File

@@ -0,0 +1,14 @@
import { NativeScriptConfig } from '@nativescript/core';
export default {
id: 'org.nativescript.dom.events.old',
appResourcesPath: '../../tools/assets/App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
},
appPath: 'src',
cli: {
packageManager: 'npm',
},
} as NativeScriptConfig;

14
apps/old/package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"main": "./src/app.ts",
"description": "Old bespoke events",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"@nativescript/core": "8.4.1"
},
"devDependencies": {
"@nativescript/android": "~8.3.0",
"@nativescript/ios": "~8.3.0",
"@nativescript/webpack": "file:../../dist/packages/nativescript-webpack.tgz"
}
}

65
apps/old/project.json Normal file
View File

@@ -0,0 +1,65 @@
{
"name": "apps-old",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/old/src",
"projectType": "application",
"prefix": "nativescript",
"namedInputs": {
"default": ["{projectRoot}/**/*"],
"production": ["!{projectRoot}/**/*.spec.ts"]
},
"targets": {
"build": {
"executor": "@nativescript/nx:build",
"options": {
"noHmr": true,
"production": true,
"uglify": true,
"release": true,
"forDevice": true
},
"dependsOn": [
{
"target": "build.all",
"projects": "dependencies"
}
]
},
"ios": {
"executor": "@nativescript/nx:build",
"options": {
"platform": "ios"
},
"dependsOn": [
{
"target": "build.all",
"projects": "dependencies"
}
]
},
"android": {
"executor": "@nativescript/nx:build",
"options": {
"platform": "android"
},
"dependsOn": [
{
"target": "build.all",
"projects": "dependencies"
}
]
},
"clean": {
"executor": "@nativescript/nx:build",
"options": {
"clean": true
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/old/**/*.ts"]
}
}
}
}

1
apps/old/references.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference path="../../references.d.ts" />

View File

@@ -0,0 +1,2 @@
<Frame defaultPage="main-page">
</Frame>

2
apps/old/src/app.scss Normal file
View File

@@ -0,0 +1,2 @@
@import 'nativescript-theme-core/scss/light';
@import 'nativescript-theme-core/scss/index';

3
apps/old/src/app.ts Normal file
View File

@@ -0,0 +1,3 @@
import { Application } from '@nativescript/core';
Application.run({ moduleName: 'app-root' });

View File

@@ -0,0 +1,7 @@
import { EventData, Page } from '@nativescript/core';
import { MainViewModel } from './main-view-model';
export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new MainViewModel();
}

View File

@@ -0,0 +1,13 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<Page.actionBar>
<ActionBar title="Plugin Demos" icon="" class="action-bar" />
</Page.actionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Button text="scrolling" tap="{{ viewDemo }}" class="btn btn-primary view-demo" />
<Button text="properties" tap="{{ viewDemo }}" class="btn btn-primary view-demo" />
</StackLayout>
</ScrollView>
</StackLayout>
</Page>

View File

@@ -0,0 +1,9 @@
import { Observable, Frame } from '@nativescript/core';
export class MainViewModel extends Observable {
viewDemo(args) {
Frame.topmost().navigate({
moduleName: `plugin-demos/${args.object.text}`,
});
}
}

View File

View File

@@ -0,0 +1,75 @@
import { Button, EventData, Page, Switch, View, getViewById, Observable, Label, PropertyChangeData } from '@nativescript/core';
export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new DemoModel(page);
}
export class DemoModel extends Observable {
private readonly manualProfiling: Switch;
private readonly automatedProfiling: Button;
private readonly target: Label;
private automatedProfilingInProgress = false;
constructor(container: View) {
super();
this.manualProfiling = getViewById(container, 'manual-profiling') as Switch;
this.automatedProfiling = getViewById(container, 'automated-profiling') as Button;
this.target = getViewById(container, 'target') as Label;
}
toggleManualProfiling({ value }: PropertyChangeData): void {
console.log(`toggleManualProfiling changed to ${value}. manualProfiling:`, this.manualProfiling);
this.updateAutomatedProfilingEnabled();
}
runAutomatedProfiling(): void {
if (this.automatedProfilingInProgress) {
return;
}
console.log(`runAutomatedProfiling. automatedProfiling:`, this.automatedProfiling);
this.automatedProfilingInProgress = true;
this.updateAutomatedProfilingEnabled();
const propName = 'arbitrary-prop';
// Initialise the target property so that the first property-setting action
// doesn't produce an outlier result due to taking a one-off code branch.
this.target.setProperty(propName, -1);
const onPropertyChange = () => {
// No-op
};
this.target.addEventListener(Observable.propertyChangeEvent, onPropertyChange, null);
const time = profile(() => {
for (let i = 0; i < 1000000; i++) {
this.target.setProperty(propName, i);
}
});
this.target.removeEventListener(Observable.propertyChangeEvent, onPropertyChange, null);
console.log(`1,000,000 runs of setProperty() took ${time} ms`);
this.automatedProfilingInProgress = false;
this.updateAutomatedProfilingEnabled();
}
private updateAutomatedProfilingEnabled(): void {
this.automatedProfiling.isEnabled = !this.automatedProfilingInProgress && !this.manualProfiling.checked;
}
}
function profile(action: () => void) {
const start = global.isIOS ? (global as any).performance.now() : __time();
action();
const stop = global.isIOS ? (global as any).performance.now() : __time();
return stop - start;
}

View File

@@ -0,0 +1,19 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<Page.actionBar>
<ActionBar title="Properties" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<ScrollView scroll="{{ onScroll }}">
<StackLayout>
<FlexboxLayout>
<Label text="Manual profiling" />
<Switch id="manual-profiling" checked="false" checkedChange="{{ toggleManualProfiling }}" />
</FlexboxLayout>
<Button id="automated-profiling" text="Automated profiling" tap="{{ runAutomatedProfiling }}" class="btn btn-primary" />
<Label id="target" text="Event target" class="bg-gold" />
</StackLayout>
</ScrollView>
</Page>

View File

@@ -0,0 +1,54 @@
import { PropertyChangeData } from '@nativescript/core/data/observable';
import { Button, EventData, Page, Switch, View, getViewById, ScrollEventData, ScrollView } from '@nativescript/core';
import { DemoSharedBase } from '@demo/shared';
export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new DemoModel(page);
}
export class DemoModel extends Observable {
private readonly manualProfiling: Switch;
private readonly automatedProfiling: Button;
private readonly scrollView: ScrollView;
private automatedProfilingInProgress = false;
constructor(container: View) {
super();
this.manualProfiling = getViewById(container, 'manual-profiling') as Switch;
this.automatedProfiling = getViewById(container, 'automated-profiling') as Button;
this.scrollView = getViewById(container, 'scrollview') as ScrollView;
// sanity check
this.scrollView.once('scroll', () => console.log('ONCE scroll'));
}
toggleManualProfiling({ value }: PropertyChangeData): void {
console.log(`toggleManualProfiling changed to ${value}. manualProfiling:`, this.manualProfiling);
this.updateAutomatedProfilingEnabled();
}
runAutomatedProfiling(): void {
if (this.automatedProfilingInProgress) {
return;
}
console.log(`runAutomatedProfiling. automatedProfiling:`, this.automatedProfiling);
this.automatedProfilingInProgress = true;
this.updateAutomatedProfilingEnabled();
this.automatedProfilingInProgress = false;
this.updateAutomatedProfilingEnabled();
}
onScroll(e: ScrollEventData): void {
console.log(`[scroll]`);
}
private updateAutomatedProfilingEnabled(): void {
this.automatedProfiling.isEnabled = !this.automatedProfilingInProgress && !this.manualProfiling.checked;
}
}

View File

@@ -0,0 +1,19 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<Page.actionBar>
<ActionBar title="Scrolling" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<ScrollView id="scrollview" scroll="{{ onScroll }}">
<StackLayout>
<FlexboxLayout>
<Label text="Manual profiling" />
<Switch id="manual-profiling" checked="false" checkedChange="{{ toggleManualProfiling }}" />
</FlexboxLayout>
<Button id="automated-profiling" text="Automated profiling" tap="{{ runAutomatedProfiling }}" class="btn btn-primary" />
<StackLayout height="2000" backgroundColor="green" />
</StackLayout>
</ScrollView>
</Page>

11
apps/old/tsconfig.json Normal file
View File

@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDirs": [".", "../.."],
"baseUrl": ".",
"paths": {
"~/*": ["src/*"],
"@demo/shared": ["../../tools/demo/index.ts"]
}
}
}

View File

@@ -0,0 +1,24 @@
const webpack = require('@nativescript/webpack');
const { resolve } = require('path');
module.exports = (env) => {
webpack.init(env);
webpack.useConfig('typescript');
webpack.chainWebpack((config) => {
// shared demo code
config.resolve.alias.set(
'@demo/shared',
resolve(__dirname, '..', '..', 'tools', 'demo')
);
});
// Example if you need to share images across demo apps:
// webpack.Utils.addCopyRule({
// from: '../../../tools/images',
// to: 'images',
// context: webpack.Utils.project.getProjectFilePath('node_modules')
// });
return webpack.resolveConfig();
};