Reduce bundle and render work with evidence
Reduce work only where evidence supports it
A catalogue with thousands of rows may waste time filtering, constructing elements, transferring unnecessary JavaScript, or laying out content. Each bottleneck has a different remedy. Use a stable synthetic workload and compare behavior before timing. The following model compares a scan of all seed records with an index for exact category queries. An index consumes memory and must be rebuilt or maintained when records change. It is unsuitable as a drop-in replacement for arbitrary substring searches.
export function makeSeeds(size){ if(!Number.isInteger(size)||size<0||size>20000) throw new RangeError('Size out of range'); return Array.from({length:size},(_,id)=>({id,category:['pea','bean','herb'][id%3],name:`Seed ${id}`}));}export const scan=(rows,category)=>rows.filter(r=>r.category===category);export function buildIndex(rows){ const index=new Map(); for(const row of rows){ if(!index.has(row.category)) index.set(row.category,[]); index.get(row.category).push(row); } return category=>[...(index.get(category)??[])];}For six records, pea returns IDs 0 and 3, bean 1 and 4, herb 2 and 5, and an unknown category returns an empty list. Both strategies return fresh arrays in the same order, sharing record objects that callers must treat as read-only. Rebuild the index when the source changes. The companion benchmark measures actual Node.js scan and indexed lookup timings over 12,000 synthetic records with the same query sequence, plus index construction separately. It does not measure React, DOM, browser responsiveness or a production workload. Read its raw samples and environment report before drawing conclusions.
Limit rendered content with accessible pagination
import React,{useState} from 'react';import {makeSeeds,scan} from './c42-l03-s03.mjs';const rows=makeSeeds(600);const pageSize=20;export default function PagedSeeds(){ const [category,setCategory]=useState('pea'); const [page,setPage]=useState(0); const matches=scan(rows,category); const pages=Math.max(1,Math.ceil(matches.length/pageSize)); return <section><h2>Seed catalogue</h2><label>Category <select value={category} onChange={e=>{setCategory(e.target.value);setPage(0);}}><option value="pea">Peas</option><option value="bean">Beans</option><option value="herb">Herbs</option></select></label> <p role="status">Page {page+1} of {pages}, {matches.length} results</p> <ul>{matches.slice(page*pageSize,(page+1)*pageSize).map(r=><li key={r.id}>{r.name}</li>)}</ul> <button type="button" disabled={page===0} onClick={()=>setPage(p=>Math.max(0,p-1))}>Previous</button> <button type="button" disabled={page>=pages-1} onClick={()=>setPage(p=>Math.min(pages-1,p+1))}>Next</button></section>;}Each category contains 200 records, so the first page shows 20 and the last page is page 10. Changing category resets the page. This is pagination, not virtualization. Virtualization keeps a moving subset of rows mounted as the user scrolls. It may improve layout and DOM costs but can disrupt browser find, screen reader access and keyboard focus when rows disappear. Test keyboard navigation and focus after page changes, including when a focused button becomes disabled; provide a deliberate focus policy where required. For virtualized interfaces verify item identity, overscan, accessible position information, focus retention and a non-virtualized or paginated alternative. Do not assume a library automatically provides all of these behaviors.
import React,{lazy,Suspense,useState} from 'react';const SeedHelp=lazy(()=>import('./SeedHelp.jsx'));export default function OptionalHelp(){ const [open,setOpen]=useState(false); return <section><button type="button" aria-expanded={open} onClick={()=>setOpen(v=>!v)}>{open?'Hide':'Show'} seed help</button> {open&&<Suspense fallback={<p role="status">Loading help...</p>}><SeedHelp/></Suspense>}</section>;}The companion SeedHelp.jsx exports the detail component. A compatible bundler may create a separate chunk loaded on demand; verify emitted files and actual requests in the Network panel. Compare initial transferred and decoded bytes and the time to open help with an eager import under cold and warm cache conditions. Add an Error Boundary around this optional section in the application shell for chunk-load failures. Splitting can reduce initial work but add latency at first use; preload only when justified. Compression, cache headers, dependency size and code execution costs are separate concerns. Compare outcomes on slower devices, not merely bundle sizes. Practice: complete the comparison checklist and keep any unmeasured result explicitly pending.