Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf] avoid double memory usage in append opcodes #1518

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 2 additions & 12 deletions packages/@glimmer/debug/lib/opcode-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ import { MachineOp, Op } from '@glimmer/vm';

import type { NormalizedMetadata } from './metadata';

function fillNulls<T>(count: number): T[] {
let arr = new Array(count);

for (let i = 0; i < count; i++) {
arr[i] = null;
}

return arr;
}

export function opcodeMetadata(
op: VmMachineOp | VmOp,
isMachine: 0 | 1
Expand All @@ -24,8 +14,8 @@ export function opcodeMetadata(
return value || null;
}

const METADATA: Nullable<NormalizedMetadata>[] = fillNulls(Op.Size);
const MACHINE_METADATA: Nullable<NormalizedMetadata>[] = fillNulls(MachineOp.Size);
const METADATA: Nullable<NormalizedMetadata>[] = new Array(Op.Size).fill(null);
const MACHINE_METADATA: Nullable<NormalizedMetadata>[] = new Array(Op.Size).fill(null);
MACHINE_METADATA[MachineOp.PushFrame] = {
name: 'PushFrame',
mnemonic: 'pushf',
Expand Down
4 changes: 2 additions & 2 deletions packages/@glimmer/runtime/lib/opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { debug, logOpcode, opcodeMetadata, recordStackSize } from '@glimmer/debug';
import { LOCAL_DEBUG, LOCAL_SHOULD_LOG } from '@glimmer/local-debug-flags';
import { valueForRef } from '@glimmer/reference';
import { assert, fillNulls, LOCAL_LOGGER, unwrap } from '@glimmer/util';
import { assert, LOCAL_LOGGER, unwrap } from '@glimmer/util';
import { $fp, $pc, $ra, $sp, Op } from '@glimmer/vm';

import type { LowLevelVM, VM } from './vm';
Expand Down Expand Up @@ -52,7 +52,7 @@ export type DebugState = {
};

export class AppendOpcodes {
private evaluateOpcode: Evaluate[] = fillNulls<Evaluate>(Op.Size).slice();
private evaluateOpcode: Evaluate[] = new Array(Op.Size).fill(null);

add<Name extends VmOp>(name: Name, evaluate: Syscall): void;
add<Name extends VmMachineOp>(name: Name, evaluate: MachineOpcode, kind: 'machine'): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export {
isSerializationFirstNode,
SERIALIZATION_FIRST_NODE_STRING,
} from './lib/is-serialization-first-node';
export { assign, entries, fillNulls, values } from './lib/object-utils';
export { assign, entries, values } from './lib/object-utils';
export * from './lib/platform-utils';
export * from './lib/present';
export {
Expand Down
10 changes: 0 additions & 10 deletions packages/@glimmer/util/lib/object-utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
export let assign = Object.assign;

export function fillNulls<T>(count: number): T[] {
let arr = new Array(count);

for (let i = 0; i < count; i++) {
arr[i] = null;
}

return arr;
}

export function values<T>(obj: { [s: string]: T }): T[] {
return Object.values(obj);
}
Expand Down