make fastCurriedFns a direct transformation

This commit is contained in:
Matthew Griffith 2021-09-23 17:55:33 -04:00
parent 83e1065d06
commit 7d15204f92
5 changed files with 5931 additions and 40 deletions

View File

@ -6,34 +6,13 @@ Compiles all the test cases and runs them via webdriver to summarize the results
*/
import {
ObjectUpdate,
Transforms,
Browser,
InlineLists,
toolDefaults,
} from '../types';
import * as Reporting from './reporting';
import * as Benchmark from './benchmark';
import * as fs from 'fs';
import * as Types from '../types'
const defaultOptions: Transforms = {
replaceVDomNode: false,
variantShapes: true,
inlineNumberToString: false,
inlineEquality: true,
inlineFunctions: true,
listLiterals: false,
passUnwrappedFunctions: true,
arrowFns: false,
shorthandObjectLiterals: false,
objectUpdate: false,
unusedValues: false,
replaceListFunctions: true,
replaceStringFunctions: true,
recordUpdates: false,
v8Analysis: true,
replacements: null
};
const options = {
compile: true,
@ -44,18 +23,20 @@ const options = {
runBenchmark: [
{
browser: Browser.Chrome,
headless: false,
headless: true,
},
// {
// browser: Browser.Firefox,
// headless: true,
// },
// {
// browser: Browser.Firefox,
// headless: true,
// },
// {
// browser: Browser.Safari,
// headless: true,
// },
],
transforms: defaultOptions
transforms:
Types.benchmarkDefaults(false, null)
// Types.previous.v1
};
@ -74,6 +55,11 @@ async function go() {
// dir: 'testcases/elm-css',
// elmFile: 'V8/Benchmark.elm',
// },
// {
// name: 'Elm CSS - Realworld',
// dir: 'testcases/elm-css-realworld',
// elmFile: 'V8/Benchmark.elm',
// },
{
name: 'Html',
dir: 'testcases/html',

View File

@ -22,8 +22,6 @@ import { createRemoveUnusedLocalsTransform } from './transforms/removeUnusedLoca
import { createPassUnwrappedFunctionsTransformer } from './transforms/passUnwrappedFunctions';
import { replaceVDomNode } from './transforms/adjustVirtualDom';
import { inlineNumberToString } from './transforms/inlineNumberToString';
import { replaceListFunctions } from './transforms/replaceListFunctions';
import { replaceStringFunctions } from './transforms/replaceStringFunctions';
import { reportFunctionStatusInBenchmarks, v8Debug } from './transforms/analyze';
import { recordUpdate } from './transforms/recordUpdate';
import * as Replace from './transforms/replace';
@ -89,11 +87,12 @@ export const transform = async (
let inlineCtx: InlineContext | undefined;
const transformations: any[] = removeDisabled([
[transforms.replacements != null, replacementTransformer ],
[transforms.replaceListFunctions, replaceListFunctions],
[transforms.replaceStringFunctions, replaceStringFunctions],
[transforms.fastCurriedFns, Replace.from_file('/../replacements/faster-function-wrappers') ],
[transforms.replaceListFunctions, Replace.from_file('/../replacements/list') ],
[transforms.replaceStringFunctions, Replace.from_file('/../replacements/string') ],
[transforms.v8Analysis, v8Debug],
[transforms.variantShapes, normalizeVariantShapes],
[transforms.inlineFunctions, createFunctionInlineTransformer(verbose)],
[transforms.inlineFunctions, createFunctionInlineTransformer(verbose, transforms.fastCurriedFns)],
[transforms.inlineEquality, inlineEquality()],
[transforms.inlineNumberToString, inlineNumberToString()],
[

View File

@ -1,5 +1,4 @@
import ts from 'typescript';
// import { matchElmSource } from './patterns';
/*
@ -94,8 +93,11 @@ function reportInlineTransformResult(ctx: InlineContext) {
console.log(`inlining ${inlined.fromRawFunc} function calls`);
}
export const createFunctionInlineTransformer = (
logOverview: boolean,
arityBasedFunctionNames: boolean,
ignoreTopLevel?: 'for tests'
): ts.TransformerFactory<ts.SourceFile> => (context) => {
return (sourceFile) => {
@ -106,7 +108,8 @@ export const createFunctionInlineTransformer = (
const splitter = createSplitterVisitor(
inlineContext,
context,
ignoreTopLevel === 'for tests'
ignoreTopLevel === 'for tests',
arityBasedFunctionNames
);
const splittedNode = ts.visitNode(sourceFile, splitter);
@ -137,7 +140,8 @@ const isTopLevelScope = (path: ts.Node[]) => {
const createSplitterVisitor = (
{ splits, partialApplications, functionsThatWrapFunctions }: InlineContext,
context: ts.TransformationContext,
ignoreTopLevel: boolean
ignoreTopLevel: boolean,
arityBasedFunctionNames: boolean
) => {
const visitor = (path: ts.Node[]) => (
node: ts.Node
@ -365,12 +369,23 @@ const createSplitterVisitor = (
// splits into
// var f = A2(g, a,b);
// var f_fn = f.f;
let inner_fn_name = 'f'
// arityBasedFunctionNames
// Normally the internal function is stored at `.f`
// However, when using fastCurriedFns, the internal function is stored at `.a{arity}`
if (arityBasedFunctionNames && partialApplication && partialApplication.funcReturnsWrapper && partialApplication.funcReturnsWrapper.resultArity != 1) {
inner_fn_name = 'a' + (partialApplication.funcReturnsWrapper.resultArity)
}
return [
node,
ts.createVariableDeclaration(
ts.createIdentifier(rawFunName),
undefined,
ts.createPropertyAccess(node.name, ts.createIdentifier('f'))
ts.createPropertyAccess(node.name, ts.createIdentifier(inner_fn_name))
),
];
}

View File

@ -1,4 +1,5 @@
import { readFilesSync } from './fs_util';
import * as Replace from './transforms/replace';
export enum Mode {
Prod = 'prod',
@ -40,6 +41,7 @@ export type Transforms = {
replaceStringFunctions: boolean;
recordUpdates: boolean;
v8Analysis: boolean;
fastCurriedFns: boolean;
replacements: { [name: string]: string } | null
};
@ -90,7 +92,8 @@ export function toolDefaults(o3Enabled: boolean, replacements: { string: string
replaceStringFunctions: false,
recordUpdates: o3Enabled,
v8Analysis: false,
replacements: replacements || readFilesSync(__dirname + '/replacements/faster-function-wrappers')
fastCurriedFns: true,
replacements: replacements
};
}
@ -111,7 +114,37 @@ export function benchmarkDefaults(o3Enabled: boolean, replacements: { string: st
replaceListFunctions: true,
replaceStringFunctions: true,
recordUpdates: o3Enabled,
v8Analysis: true,
replacements: replacements || readFilesSync(__dirname + '/replacements/faster-function-wrappers')
v8Analysis: false,
fastCurriedFns: true,
replacements: replacements
};
}
export type Previous = {
v1: Transforms
};
export const previous: Previous =
{ v1: {
replaceVDomNode: false,
variantShapes: true,
inlineNumberToString: false,
inlineEquality: true,
inlineFunctions: true,
listLiterals: false,
passUnwrappedFunctions: true,
arrowFns: false,
shorthandObjectLiterals: false,
objectUpdate: false,
unusedValues: false,
replaceListFunctions: false,
replaceStringFunctions: false,
recordUpdates: false,
v8Analysis: false,
fastCurriedFns: false,
replacements: null
}
}

5858
yarn.lock Normal file

File diff suppressed because it is too large Load Diff