Skip to content

perf(button): memoize icon, label and badge rendering#8530

Open
sudheerchauhan452-lab wants to merge 2 commits intoprimefaces:masterfrom
sudheerchauhan452-lab:perf/button-memoization
Open

perf(button): memoize icon, label and badge rendering#8530
sudheerchauhan452-lab wants to merge 2 commits intoprimefaces:masterfrom
sudheerchauhan452-lab:perf/button-memoization

Conversation

@sudheerchauhan452-lab
Copy link
Copy Markdown

@sudheerchauhan452-lab sudheerchauhan452-lab commented Apr 15, 2026

Closes #8526

Summary

This PR improves the performance of the Button component by memoizing the rendering of icon, label, and badge using React.useMemo.

Changes

  • Memoized icon, label, and badge computations
  • Inlined helper logic to avoid hook dependency warnings
  • Ensured hooks are not conditionally called
  • Added proper dependency arrays

Benefits

  • Reduces unnecessary computations during re-renders
  • Improves performance in high-frequency rendering scenarios (e.g., lists, forms)
  • Aligns with React performance best practices
  • No breaking changes

Testing

  • Verified button rendering with:
    • icon changes
    • loading state
    • label updates
    • badge updates
  • Ensured no UI regressions

Notes

This change maintains full backward compatibility and does not alter the public API.

Optimize Button component by memoizing icon, label and badge computations using React.useMemo.

- Prevents unnecessary recalculations on re-renders
- Improves performance in high-frequency render scenarios
- Inlined helper logic to avoid hook dependency issues
- Maintains full backward compatibility"
@github-actions
Copy link
Copy Markdown

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@melloware melloware added the Type: Performance Issue is performance or optimization related label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Performance Issue is performance or optimization related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enchancement: Memoize UI builders in Button

3 participants