Skip to content

Commit

Permalink
Better production stripping - 61KB smaller, 63% of main's size, 2.7…
Browse files Browse the repository at this point in the history
…x smaller (#149)

* Progress?

* progress

* lint:fix

* Bump to released version of dev/compile
  • Loading branch information
NullVoxPopuli authored Jan 12, 2024
1 parent d342d90 commit 9b5a07d
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 151 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
},
"overrides": {
"@rollup/pluginutils": "latest",
"@starbeam-dev/compile": "1.2.0",
"@types/eslint": "$@types/eslint",
"@types/node": "$@types/node",
"eslint": "$eslint",
Expand Down
23 changes: 12 additions & 11 deletions packages/universal/debug/src/call-stack/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export class EntryPoints {
this: void,
options?:
| {
caller?: CallStack | undefined;
description?: EntryPointDescriptionArg | string | undefined;
force?: boolean | undefined;
}
caller?: CallStack | undefined;
description?: EntryPointDescriptionArg | string | undefined;
force?: boolean | undefined;
}
| EntryPointDescriptionArg
| EntryPoint
| string,
): EntryPoint {
): void {
if (options instanceof EntryPointImpl) {
ENTRY_POINTS.#upsert(options, false);
return options;
return;
}

let caller: CallStack | undefined;
Expand All @@ -64,7 +64,8 @@ export class EntryPoints {
force = false;
}

return ENTRY_POINTS.mark(caller, description, force);
ENTRY_POINTS.mark(caller, description, force);
return;
}

#entry: EntryPointImpl | undefined;
Expand Down Expand Up @@ -199,10 +200,10 @@ function stringify(value: unknown): string {
function collectionOp(
arg: [
operation:
| "collection:has"
| "collection:get"
| "collection:insert"
| "collection:delete",
| "collection:has"
| "collection:get"
| "collection:insert"
| "collection:delete",
entity: DescriptionDetails | string | undefined,
key: unknown,
],
Expand Down
36 changes: 26 additions & 10 deletions packages/universal/debug/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,29 @@ const untrackedReadBarrier = (() => {
/* FIXME: do nothing for now */
}) satisfies DebugRuntime["untrackedReadBarrier"];

export default {
Desc,
callerStack,
getUserFacing,
untrackedReadBarrier,
describe,
describeTagged,
markEntryPoint,
getEntryPoint,
} satisfies DebugRuntime;
let debugEnv = {
Desc: (() => undefined),
callerStack: () => undefined,
getUserFacing: (x) => x,
untrackedReadBarrier: () => undefined,
describe: () => '',
describeTagged: () => '',
markEntryPoint: () => undefined,
getEntryPoint: () => undefined,
} as DebugRuntime;

if (import.meta.env.DEV) {
debugEnv = {
Desc,
callerStack,
getUserFacing,
untrackedReadBarrier,
describe,
describeTagged,
markEntryPoint,
getEntryPoint,
} satisfies DebugRuntime;
}

export default debugEnv;

32 changes: 17 additions & 15 deletions packages/universal/debug/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import { defineDebug } from "@starbeam/reactive";

import debug from "./debug.js";

if (
(globalThis.Buffer as BufferConstructor | undefined) === undefined &&
typeof require === "function"
) {
try {
// this is for CJS only, so require is the only option here
// eslint-disable-next-line @typescript-eslint/no-var-requires
const buffer = require("node:buffer") as { Buffer: BufferConstructor };
if (import.meta.env.DEV) {
if (
(globalThis.Buffer as BufferConstructor | undefined) === undefined &&
typeof require === "function"
) {
try {
// this is for CJS only, so require is the only option here
// eslint-disable-next-line @typescript-eslint/no-var-requires
const buffer = require("node:buffer") as { Buffer: BufferConstructor };
globalThis.Buffer = buffer.Buffer;
} catch {
// ignore
}
} else {
const buffer = await import("node:buffer");
globalThis.Buffer = buffer.Buffer;
} catch {
// ignore
}
} else {
const buffer = await import("node:buffer");
globalThis.Buffer = buffer.Buffer;
}

defineDebug(debug);
defineDebug(debug);
}
2 changes: 1 addition & 1 deletion packages/universal/debug/tests/stack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Error stacks", () => {
});

function anOuterFunction(): CallStack | undefined {
return DEBUG.callerStack();
return void DEBUG.callerStack();
}

function callerStackInArgs(
Expand Down
72 changes: 36 additions & 36 deletions packages/universal/interfaces/src/debug/debug-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { DescFn, DescriptionDetails } from "./description.js";

export type DescribeOptions =
| {
id: boolean | undefined;
}
id: boolean | undefined;
}
| undefined;

export interface DebugRuntime {
Expand Down Expand Up @@ -41,14 +41,14 @@ export interface DebugRuntime {
markEntryPoint: (
options?:
| {
caller?: CallStack | undefined;
description?: EntryPointDescriptionArg | string | undefined;
force?: boolean | undefined;
}
caller?: CallStack | undefined;
description?: EntryPointDescriptionArg | string | undefined;
force?: boolean | undefined;
}
| EntryPointDescriptionArg
| EntryPoint
| string
) => EntryPoint;
) => void;
getEntryPoint: () => EntryPoint | undefined;

readonly Desc: DescFn;
Expand All @@ -68,36 +68,36 @@ export interface EntryPointDescription {
export type EntryPointDescriptionArg =
| ["label", string]
| [
operation: "reactive:read" | "reactive:write" | "reactive:call",
entity: DescriptionDetails | string | undefined,
api?: PropertyKey
]
operation: "reactive:read" | "reactive:write" | "reactive:call",
entity: DescriptionDetails | string | undefined,
api?: PropertyKey
]
| [
operation:
| "object:get"
| "object:set"
| "object:has"
| "object:call"
| "object:define"
| "object:delete"
| "object:meta:get",
entity: DescriptionDetails | string | undefined,
target: PropertyKey
]
operation:
| "object:get"
| "object:set"
| "object:has"
| "object:call"
| "object:define"
| "object:delete"
| "object:meta:get",
entity: DescriptionDetails | string | undefined,
target: PropertyKey
]
| [
operation: "object:meta:keys",
entity: DescriptionDetails | string | undefined
]
operation: "object:meta:keys",
entity: DescriptionDetails | string | undefined
]
| [
operation: "function:call",
entity: DescriptionDetails | string | undefined
]
operation: "function:call",
entity: DescriptionDetails | string | undefined
]
| [
operation:
| "collection:has"
| "collection:get"
| "collection:insert"
| "collection:delete",
entity: DescriptionDetails | string | undefined,
key: unknown
];
operation:
| "collection:has"
| "collection:get"
| "collection:insert"
| "collection:delete",
entity: DescriptionDetails | string | undefined,
key: unknown
];
23 changes: 17 additions & 6 deletions packages/universal/verify/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { isOneOf as isOneOfDev } from "./src/assertions/multi.js";
import { hasType as hasTypeDev } from "./src/assertions/types.js";
import type { VerifyFn } from "./src/verify.js";
import { verified as verifiedDev, verify as verifyDev } from "./src/verify.js";
import {
expected as expectedDev,
verified as verifiedDev,
verify as verifyDev
} from "./src/verify.js";

const noop: unknown = () => { };

export {
exhaustive,
Expand All @@ -12,13 +20,16 @@ export {
isPresent,
isWeakKey,
} from "./src/assertions/basic.js";
export { isOneOf } from "./src/assertions/multi.js";
export { hasType, type TypeOf } from "./src/assertions/types.js";
export { type Expectation, expected, VerificationError } from "./src/verify.js";
export { type TypeOf } from "./src/assertions/types.js";
export { type Expectation, VerificationError } from "./src/verify.js";

export const expected: typeof expectedDev = import.meta.env.DEV ? expectedDev : (noop as typeof expectedDev)
export const hasType: typeof hasTypeDev = import.meta.env.DEV ? hasTypeDev : (noop as typeof hasTypeDev)
export const isOneOf: typeof isOneOfDev = import.meta.env.DEV ? isOneOfDev : (noop as typeof isOneOfDev)

export const verify: VerifyFn = import.meta.env.DEV
? verifyDev
: verifyDev.noop;
: (noop as VerifyFn);
export const verified: (typeof verifiedDev)["noop"] = import.meta.env.DEV
? verifiedDev
: verifiedDev.noop;
: (noop as typeof verifiedDev);
Loading

0 comments on commit 9b5a07d

Please sign in to comment.