Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): take the profiler's call sites back out

Elian Doranecab4dd6ef87
diff --git a/apps/client/src/entities/fattribute.ts b/apps/client/src/entities/fattribute.ts
index c4bc977c66..df5dd9a52c 100644
--- a/apps/client/src/entities/fattribute.ts
+++ b/apps/client/src/entities/fattribute.ts
@@ -1,6 +1,5 @@
import { promotedAttributeDefinitionParser } from "@triliumnext/commons";
-import { perfSpan } from "../services/debug_perf.js";
import type { Froca } from "../services/froca-interface.js";
/**
@@ -88,14 +87,7 @@ class FAttribute {
}
getDefinition() {
- // Re-parses the definition string on every call, so a caller in a render path pays for it
- // once per attribute per render; the span is what makes that visible.
- const endSpan = perfSpan("FAttribute.getDefinition");
- try {
- return promotedAttributeDefinitionParser.parse(this.value);
- } finally {
- endSpan();
- }
+ return promotedAttributeDefinitionParser.parse(this.value);
}
isDefinitionFor(attr: FAttribute) {
diff --git a/apps/client/src/services/debug_perf.ts b/apps/client/src/services/debug_perf.ts
index 97b096a729..e525f193f5 100644
--- a/apps/client/src/services/debug_perf.ts
+++ b/apps/client/src/services/debug_perf.ts
@@ -15,6 +15,12 @@
*
* Spans additionally land on the User Timing track via `performance.measure()`, so a DevTools
* performance capture shows them lined up against the long tasks they explain.
+ *
+ * Nothing calls into this by default, and that is deliberate rather than an oversight: instrument
+ * whatever is being investigated for as long as it takes to answer the question, then take the call
+ * sites back out. Adding the first `perfSpan()` or `perfCount()` anywhere is what pulls this module
+ * into the bundle, which is also what puts `triliumPerf` on `window` -- so there is nothing to arm
+ * beyond the call site itself.
*/
interface Counter {
diff --git a/apps/client/src/widgets/attribute_widgets/UserAttributesList.tsx b/apps/client/src/widgets/attribute_widgets/UserAttributesList.tsx
index f7d9ddea35..d3e2ddcbce 100644
--- a/apps/client/src/widgets/attribute_widgets/UserAttributesList.tsx
+++ b/apps/client/src/widgets/attribute_widgets/UserAttributesList.tsx
@@ -7,7 +7,6 @@ import { useState } from "preact/hooks";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
import { getReadableTextColor } from "../../services/css_class_manager";
-import { perfSpan } from "../../services/debug_perf";
import { formatDateTime } from "../../utils/formatters";
import { useTriliumEvent } from "../react/hooks";
import Icon from "../react/Icon";
@@ -117,15 +116,6 @@ function buildUserAttribute(attr: AttributeWithDefinitions): ComponentChildren {
}
function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
- const endSpan = perfSpan("UserAttributesList.getAttributesWithDefinitions");
- try {
- return gatherAttributesWithDefinitions(note, attributesToIgnore);
- } finally {
- endSpan();
- }
-}
-
-function gatherAttributesWithDefinitions(note: FNote, attributesToIgnore: string[]): AttributeWithDefinitions[] {
const attributeDefintions = note.getAttributeDefinitions();
const result: AttributeWithDefinitions[] = [];
for (const attr of attributeDefintions) {
diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx
index efaa6f8937..655b9d2e8a 100644
--- a/apps/client/src/widgets/collections/board/card.tsx
+++ b/apps/client/src/widgets/collections/board/card.tsx
@@ -6,7 +6,6 @@ import BoardApi from "./api";
import { BoardActionsContext, TitleEditor } from ".";
import { ContextMenuEvent } from "../../../menus/context_menu";
import { openNoteContextMenu } from "./context_menu";
-import { perfCount } from "../../../services/debug_perf";
import { t } from "../../../services/i18n";
import UserAttributesDisplay from "../../attribute_widgets/UserAttributesList";
import { useNoteIcon, useTriliumEvent } from "../../react/hooks";
@@ -41,8 +40,6 @@ function Card({
*/
isEditing: boolean
}) {
- perfCount("board.card.render");
-
const { setBranchIdToEdit, setDraggedCard } = useContext(BoardActionsContext);
const colorClass = note.getColorClass() || '';
const editorRef = useRef<HTMLInputElement>(null);
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index ee1525efff..2cc303850e 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -1,10 +1,9 @@
import "./index.css";
import { createContext, TargetedKeyboardEvent } from "preact";
-import { Dispatch, StateUpdater, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
+import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
-import { perfLog, perfSpan } from "../../../services/debug_perf";
import { t } from "../../../services/i18n";
import type LoadResults from "../../../services/load_results";
import { isIMEComposing } from "../../../services/shortcuts";
@@ -139,22 +138,9 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
dropTarget
}), [ branchIdToEdit, columnNameToEdit, draggedCard, draggedColumn, dropPosition, dropTarget ]);
- /**
- * Closed by the layout effect below rather than at the end of `refresh()`, so the span covers
- * the commit the refresh causes and not just the state write, which Preact defers.
- */
- const renderSpanRef = useRef<(() => void) | null>(null);
-
- useLayoutEffect(() => {
- renderSpanRef.current?.();
- renderSpanRef.current = null;
- });
-
function refresh() {
- const endData = perfSpan("board.getBoardData");
getBoardData(parentNote, statusAttributeWithPrefix, viewConfig ?? {}, includeArchived, statusDefinition?.options ?? [])
.then(({ byColumn, columns, newPersistedData, isInRelationMode }) => {
- endData();
setByColumn(byColumn);
setIsRelationMode(isInRelationMode);
setColumns(columns);
@@ -194,22 +180,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
setDefinitionRevision(revision => revision + 1);
}
- const endMatch = perfSpan("board.matchRefreshReason");
- const reason = findRefreshReason(loadResults, api.statusAttribute, noteIds, parentNote.noteId);
- endMatch();
-
- if (reason) {
- // Logged when the redraw lands rather than when it starts, so each line carries its own
- // cost. A STALL line cannot answer that on a saturated main thread -- it spans every
- // redraw that fell inside one contiguous busy period.
- const endRefresh = perfSpan(`board.refreshToPaint[${reason}]`);
- renderSpanRef.current = () => perfLog("board.refreshToPaint", {
- reason,
- ms: Math.round(endRefresh()),
- cards: noteIds.length,
- changedNotes: loadResults.getNoteIds().length
- });
-
+ if (findRefreshReason(loadResults, api.statusAttribute, noteIds, parentNote.noteId)) {
refresh();
}
});