Improving EUI architecture starts with measurement, not refactoring: profile the component tree and bundle first, fix the highest-cost rendering and styling problems, and only then restructure shared code. EUI here means Elastic UI, the open-source React component library Elastic builds for its Kibana and Elasticsearch interfaces. The library's own CSS-in-JS styling engine often dominates cost in data-heavy apps, so the biggest wins usually come from bounding re-renders, scoping theme/global styles, and tree-shaking imports rather than from moving folders around. Treat every change as an experiment with a before/after profile.

This guide works through the whole pipeline: profiling, render control, styling and theming, bundle size, composition patterns, versioning, and the limits you will hit. The advice assumes a React application using @elastic/eui on a modern browser; the version matters because EUI's styling internals have changed across major releases, so confirm current API names against your installed version before applying code changes.

Start With a Profile of the Actual Application

The first step is always a prerequisite: a reproducible baseline. You cannot improve architecture you have not measured, and EUI apps have several plausible bottlenecks that look similar but need different fixes.

Setup: run the app in development with React DevTools installed, then capture a production build with source maps enabled for performance profiling—development-mode React is several times slower and distorts timings. Use Chrome's Performance panel for a recorded interaction, React DevTools Profiler for commit-level render counts, and your bundler's analyzer for bundle composition. Fix the workload first: pick one representative screen, such as a table page with filters, and record the same interaction before and after each change.

1: Record a baseline interaction in the Performance panel; note scripting, rendering, and styling time separately. 2: Open the React DevTools Profiler, enable "Highlight updates," and interact with the screen to see which components re-render. 3: Sort commits by duration and identify the components that appear in most commit flame graphs, not just the longest single commit—frequent small renders matter as much as rare slow ones. 4: Run the bundle analyzer and list the top modules by parsed size, marking which originate from EUI and its transitive dependencies. 5: Write down three to five candidate problems with numbers attached (for example, "table body re-renders on every keystroke in the filter, ~40 ms per render").

Success check: you have a named component or bundle chunk, a measured cost, and a repeatable interaction. If a component does not appear in the flame graph, it is not your problem yet. Stop and reconsider before restructuring anything—chasing unmeasured architecture changes is the most common way these projects waste time.

Control Re-renders at the Component Boundary

The most frequent architectural cost in EUI applications is re-rendering broad subtrees when a small state change occurs. This is a React issue, but EUI components make it visible because many of them (tables, popovers, form controls) are relatively expensive to render and restyle.

The mechanism is straightforward: when a parent re-renders, children re-render unless memoized or unless their props are stable. Inline object and function props break memoization because they are new references on every render.

Hoist static props (column definitions, options arrays, callbacks) to module scope or useMemo/useCallback them when they depend on state. Wrap expensive leaf components in React.memo, but only where the profiler shows wasted renders; blanket memoization adds comparison cost and complexity without guaranteed benefit. Keep state as local as possible. A filter input that writes to a top-level context re-renders the whole page; local state plus a narrow subscription does not. For frequently updated values (search text, scroll position), consider deferring the expensive subtree with useDeferredValue or an explicit transition so typing stays responsive while the table catches up.

A worked example: a filterable EuiBasicTable whose parent stores filter text in shared state will re-render every row's cell renderer on each keystroke. Moving the text to a sibling component that only passes a debounced value down, and memoizing the table's column props, typically collapses dozens of renders per keystroke into one per debounce interval. Instrument with the Profiler to confirm the render count drops; if it does not, the props were not actually stable.

Scope Styling and Theming to Avoid Global Recompilation

EUI's styling layer is the area most specific to this library and the one most often misdiagnosed. EUI has used both Sass/compiled CSS and an Emotion-based CSS-in-JS engine across versions; in Emotion-based setups, styled components generate and insert styles at runtime, and theme changes or dynamic props can trigger style recalculation across many components. A global theme toggle or a context update that changes the theme object can therefore cause a wide, expensive restyle.

The practical architecture fixes:

Keep theme objects stable. Create the EuiThemeProvider (or the version-appropriate theme provider) value once at the app root and avoid recreating theme objects inside render functions; a new object identity each render forces downstream consumers to re-evaluate. Avoid passing rapidly changing values as style props to EUI components. If a component's style prop depends on scroll position or animation state, you are asking the styling engine to recompute on every frame. Prefer EUI's built-in props and design tokens over ad hoc overrides. Fewer bespoke style overrides mean fewer dynamic style objects and less recalculation. Limit EuiGlobalStyles and any global reset to a single mount. Duplicate global style providers in nested layouts multiply work. For large, mostly static lists, consider CSS-first approaches (plain class names or static stylesheets) for the hot path, reserving runtime styling for interactive elements.

There is a version caveat worth stating plainly: EUI's styling implementation has shifted between major versions, and exact provider names, hook names, and whether styles compile at build time or runtime depend on the installed version. Check the changelog for your version before assuming a given API exists. The principle—stabilize theme identity, reduce dynamic style inputs—holds across implementations, but the code does not.

Success check: toggle the theme or trigger the suspected state change and confirm in the Performance panel that styling/recalculation time drops and that unrelated components no longer flash in the DevTools highlight. If restyle time is unchanged, the cost is elsewhere—often genuine layout work from a large table rather than the styling engine.

Reduce Bundle Size With Deliberate Imports

Bundle size is an architectural concern because it determines what ships to users, and EUI is a large library with many components and icon sets. The standard improvement is to ensure tree-shaking actually works: import only the components you use, keep your bundler in production mode, and verify with the analyzer that unused EUI modules are absent.

Checklist and order of operations:

1: Confirm production builds enable minification and dead-code elimination; development builds will not show the savings. 2: Import components from the package root in a way your bundler can statically analyze (named imports from the package entry), and verify side-effect flags in the library's package metadata are not defeating tree-shaking. 3: Audit icon usage. EUI ships large icon sets; importing the full set when you use a handful is a common bloat source. Use the version's documented per-icon import path where available. 4: Check for duplicate copies of EUI or its styling dependencies in the dependency graph; two copies mean duplicated code and, in CSS-in-JS setups, duplicated runtime state. 5: Measure parsed and gzipped size after each change, not just raw bytes.

A reproducible check: the analyzer should show your app's EUI footprint shrinking in proportion to removed imports. If it does not, suspect CommonJS interop or side-effect declarations rather than assuming the import style is wrong—this is where reading the library's packaging configuration pays off.

Compose for Scale: Tables, Virtualization, and Providers

EUI is used heavily for data tables and dashboards, and composition choices there have outsized cost. Three patterns matter most:

Large tables. Rendering thousands of rows into the DOM is slow regardless of library. Pagination or windowing (rendering only visible rows) is the architectural fix; EUI's table components support pagination and sorting, and for very large datasets a virtualization layer is the standard approach. Keep cell renderers pure and memoized so scrolling does not recompute formatting.

Provider placement. Put the theme provider and any EUI context at the highest stable point in the tree, but keep frequently changing application state out of that same provider. Mixing theme context with app state couples unrelated updates.

Layout boundaries. EuiFlexGroup, EuiPanel, and related layout components are cheap individually but compound in deeply nested trees. Flatten repetitive wrappers where the profiler shows layout components consuming render time, and prefer a single grid over chains of nested flex containers for uniform layouts.

Verification for tables: after windowing or memoizing cells, scroll a large table while recording; frame time should stay smooth and the Profiler should show cell components not re-rendering during scroll.

Keep EUI Current and Manage Upgrades as Architecture Work

EUI major versions carry breaking changes to styling and component APIs, so upgrades are architectural decisions, not routine bumps. The improvement is not "always use the latest"—it is a controlled upgrade process with evidence.

Read the changelog for every major version between yours and the target, listing removed or renamed components, provider changes, and styling engine changes. Upgrade in a branch, run the profiler baseline again on the same representative screen, and compare. A performance regression after an upgrade is valuable information, not an automatic revert. Remove deprecated-pattern workarounds after an upgrade; stacked overrides for old behavior often survive for years and silently add restyle cost. Pin versions and test in CI with the production build configuration so bundle-size and timing drift is visible per release.

A specific edge case: applications that patched EUI's styles with custom Sass or global CSS may break silently when the styling engine changes, because the generated class names or variables differ. The supported approach is to migrate overrides to the version's documented theming API, and to confirm visually and with the profiler that the override is gone rather than merely inert.

Know the Limits and When to Step Back

Not every problem is an architecture problem. Recognizing the boundary prevents wasted refactors.

Genuine layout cost from very large DOM trees will not be fixed by memoization; reduce rendered nodes instead. If profiling shows most time in browser paint or layout rather than script, styling or component structure is not the lever. If the CPU profile is dominated by work inside EUI internals that your app cannot influence, an upgrade or a different component choice—not a restructure—is the relevant option. If bundle size is dominated by dependencies other than EUI, EUI-specific tree-shaking will not move the needle enough.

Stop condition: if sustained profiling shows the cost is structural (for example, rendering data you do not need on screen), fix the data and rendering model first; component-level tuning will not compensate. And if your changes repeatedly regress measurements you cannot explain, revert them and re-establish the baseline rather than building on unstable assumptions.

Checking Your Work Without Guesswork

Every recommendation above should end in a measurement, and the checks are simple: the same interaction recorded before and after, the render count in the Profiler, the styling time in the Performance panel, and the parsed size in the analyzer. Keep the baseline screen and interaction fixed across the project so numbers stay comparable. Because EUI's exact APIs and styling internals vary by version, verify each code change against your installed version's documentation rather than older examples, and note the version and date alongside your results. Architecture improvement here is cumulative and empirical: bound the renders, stabilize the theme, trim the bundle, and keep the library current—then confirm each gain on the profile.