Skip to content

Commit

Permalink
Reduce shape changes in render hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed May 25, 2022
1 parent 738f6f2 commit 9312648
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/data-grid/cells/cell-types.ts
Expand Up @@ -30,10 +30,10 @@ interface DrawArgs<T extends InnerGridCell> extends BaseDrawArgs {

// intentionally mutable
export interface PrepResult {
font?: string;
fillStyle?: string;
font: string | undefined;
fillStyle: string | undefined;
renderer: {};
deprep?: (args: Pick<BaseDrawArgs, "ctx">) => void;
deprep: ((args: Pick<BaseDrawArgs, "ctx">) => void) | undefined;
}

type DrawCallback<T extends InnerGridCell> = (args: DrawArgs<T>) => void;
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/data-grid/data-grid-render.tsx
Expand Up @@ -149,14 +149,12 @@ export function drawCell(
}
const partialPrepResult = r.renderPrep?.(args, lastPrep);
r.render(args);
if (partialPrepResult !== undefined) {
partialPrepResult.renderer = r;
result = partialPrepResult as PrepResult;
} else {
result = {
renderer: r,
};
}
result = {
deprep: partialPrepResult?.deprep,
fillStyle: partialPrepResult?.fillStyle,
font: partialPrepResult?.font,
renderer: r,
};
}
});
if (needsAnim) enqueue?.([col, row]);
Expand Down

0 comments on commit 9312648

Please sign in to comment.