Skip to content

Partial-state-saving and component-tree-walk performance improvements#5778

Merged
BalusC merged 5 commits into
4.1from
tree_walk_performance
Jun 8, 2026
Merged

Partial-state-saving and component-tree-walk performance improvements#5778
BalusC merged 5 commits into
4.1from
tree_walk_performance

Conversation

@BalusC

@BalusC BalusC commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #5753 — partial-state-saving and component-tree-walk performance, all behaviour-neutral (impl unit tests + TCK pass):

  • Don't persist re-derivable composite cc.attrs expressions as per-component state deltas under PSS — buildView re-derives them on every postback. ~18% off both RESTORE_VIEW and RENDER_RESPONSE on composite-heavy views.
  • Skip the restore traversal when the saved view holds no per-component delta (view-root-only), mirroring MyFaces' restoreViewRootOnlyFromMap.
  • Skip the add/remove publish-walk when event processing is suppressed (e.g. during a PSS restore) — publishEvent is a no-op there anyway.
  • Initial-state mark walks: index loops instead of allocating getFacetsAndChildren() iterators, and skip the per-node dynamic-marker probe when the view has no dynamic actions.
  • Reuse a request-shared StringBuilder for client-id construction.

🤖 Generated with Claude Code

BalusC and others added 5 commits June 8, 2026 09:27
…pressed

doPostAddProcessing/doPreRemoveProcessing ran the full publishAfterViewEvents/disconnectFromView walk even when FacesContext.isProcessingEvents() is false (e.g. during a partial-state-saving restore or view-metadata build). While suppressed, Application.publishEvent is a no-op, so that walk does nothing but pay its per-node cost -- pushing/popping the EL stack and re-checking child/facet counts at every node.

Honor isProcessingEvents(): when it is false, take a lean updateInView walk that only maintains the in-view flag (and clears compositeParent on removal) -- the publishing walks' sole non-event side effects -- via a plain index loop, avoiding the getFacetsAndChildren() iterator allocation. Behaviour is unchanged: no event would fire while suppressed anyway. Mirrors MyFaces' _updateInView fast path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
addParentId allocated a fresh StringBuilder per component to build "parentId:childId"; in a deep NamingContainer tree that is one allocation per node per client-id resolution. Reuse a FacesContext-scoped StringBuilder instead (the parent id is already resolved to a String before this runs, and the builder is filled and toString()'d in one uninterrupted step, so the shared instance is never re-entered). Mirrors MyFaces' SharedStringBuilder.

Cuts the per-component StringBuilder/char[] allocation in client-id building; no behaviour change (verified: component unit tests + a 3000-postback composite-heavy bench).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… delta

FaceletPartialStateManagementStrategy.restoreView always ran a full visitTree over every component to apply saved per-component state, even for static or low-delta views whose saved state map carries nothing to restore. The traversal still paid getClientId + state lookup + EL push/pop at every node for no effect.

Short-circuit it: when there are no saved dynamic actions and the state map holds no per-component delta (or only the view root's own), restore the view root in isolation and skip the traversal. Any component whose state actually changed carries a non-null delta that forces the full walk, so this is behaviour-neutral. Mirrors MyFaces' restoreViewRootOnlyFromMap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ial state saving

A composite component's declared attribute expressions (e.g. cc:attribute value="#{...}") are re-applied from the Facelet on every (re)build via CompositeExpressionMetadata.applyMetadata -> setValueExpression. On a postback rebuild the tree is already initial-state-marked and IS_BUILDING_INITIAL_STATE is not set, so each expression was recorded as a per-component state delta -- one StateHolderSaver per composite, saved and restored on every postback even though buildView reconstructs it identically. The initial GET stores it as initial state, so the redundant delta only appears from the first postback on and then persists.

This is full-state-saving-era behaviour: under FSS the tree is restored purely from serialized state, so the expression must be saved; under PSS buildView re-derives it and saving it is pure redundancy. Regular components avoid this because their attributes are re-applied only when new to the tree; composites re-apply unconditionally.

Under partial state saving, write the composite attribute expression as initial state (clear/set/mark) so it stays out of the saved delta; guarded on PSS, since under FSS the component is never initial-state-marked and the branch is a no-op. On composite-heavy (500 composites) this drops 500 per-postback deltas, cutting RESTORE_VIEW and RENDER_RESPONSE (which runs saveView) ~18% each on Tomcat. All impl unit tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
initial-state walks

markInitialState and markInitialStateIfNotMarked walk the whole
component tree after every (re)build, iterating each node via
getFacetsAndChildren() -- which allocates a Collections.unmodifiable
view plus its iterator at every non-leaf node, purely for an
immutable-iteration contract these internal walks don't need. Replace
with direct index loops over getChildren() and getFacets().values(),
matching the pattern the lifecycle process* walks and updateInView
already use.

markInitialStateIfNotMarked additionally did a reflective
getAttributes().containsKey(DYNAMIC_COMPONENT) at every node to leave
dynamically added components unmarked. When the view carries no dynamic
actions -- the common case -- no component bears that marker, so thread
the dynamic-action presence (known after reapplyDynamicActions ran) down
the walk and skip the probe entirely then.

Behaviour-neutral: both walks mark exactly the same components as before
(impl unit tests pass). This is allocation/CPU hygiene, not a measurable
speedup -- flat on the composite-heavy latency bench, where the per-node
savings sit below the dominant state-helper and render costs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@BalusC BalusC merged commit 98c6640 into 4.1 Jun 8, 2026
2 of 3 checks passed
@BalusC BalusC deleted the tree_walk_performance branch June 8, 2026 15:18
BalusC added a commit that referenced this pull request Jun 8, 2026
BalusC added a commit that referenced this pull request Jun 8, 2026
@BalusC BalusC added this to the 4.1.10 milestone Jun 8, 2026
BalusC added a commit that referenced this pull request Jun 8, 2026
@BalusC BalusC mentioned this pull request Jun 8, 2026
pzygielo pushed a commit to pzygielo/mojarra that referenced this pull request Jun 8, 2026
Omits eclipse-ee4j#5777's Cache get()-probe commit: 4.0's Cache.get() already probes
with get() before putIfAbsent (it never switched to computeIfAbsent), so
that change is a no-op on 4.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant