Profile a Real Browser Interaction
Performance debugging measures where time is spent during a repeatable interaction, forms a hypothesis about the cost, and verifies a change while preserving the required behavior. Faster-looking code is not evidence of a measured improvement.
Observe an interaction, identify the work responsible for the delay, and measure the same interaction after a specific change.
Define the observation before editing
A blog list takes time to render a large collection. Record what 'done' means: the correct number of items appears, titles are correct, and the interaction remains usable. A faster function that silently drops records is not an improvement. Use the same dataset, viewport and interaction when comparing versions.
300 article records→300 correct visible itemsRun a small, measurable render
Both buttons render exactly 300 items. The direct version appends them individually; the other creates a DocumentFragment and replaces the list once. The displayed duration uses performance.now around the synchronous DOM work. It does not include all later browser layout, paint or compositing work, and it does not prove one strategy always wins. Browser optimizations, the document and the workload can change the result.
Record the whole interaction in Chromium DevTools
Open DevTools for the example's frame, then open the Performance panel. Start a recording, activate one render, wait for the visible result, and stop. Locate the interaction and inspect the main-thread work around it. Distinguish JavaScript execution from style recalculation, layout and paint. Use the call tree or bottom-up view to locate repeated work rather than guessing from the longest-looking source file.
Record both versions several times. Keep correctness checks visible. If a trace shows repeated forced layout, look for alternating style writes and layout reads such as offsetHeight; merely creating a fragment does not fix every read/write pattern. If the cost is a CPU-heavy transformation, changing CSS may not address the bottleneck. If it is network waiting, a tight-loop microbenchmark misses the user's problem entirely.
The browser console's CPU and network throttling tools can help reproduce conditions, but report the chosen settings. Do not publish one machine's millisecond result as a universal guarantee. Garbage collection, JIT compilation, extensions and background activity can affect a run. Warm-up and repetition help characterize variation, not erase it.
Optimize the data path deliberately
For repeated lookup by ID, build a Map once when the data changes rather than repeatedly scanning an unchanged array for every query. That introduces an index-maintenance cost and extra memory, so it is useful only when the workload justifies it. Map's specification requires average sublinear access; it does not mandate a universal worst-case constant-time implementation.
The graded task checks lookup behavior and result order. It does not measure speed or prove a particular implementation strategy. Use a profile to evaluate an optimization after the correctness tests pass. Write down a before/after observation, the preserved behavior, and one limitation of the measurement.