Skip to content

Fix Pandas styler performance regression#12422

Merged
lukasmasuch merged 11 commits intodevelopfrom
fix/pandas-styler-performance-regression
Sep 10, 2025
Merged

Fix Pandas styler performance regression#12422
lukasmasuch merged 11 commits intodevelopfrom
fix/pandas-styler-performance-regression

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Sep 3, 2025

Describe your changes

The change to use iloc instead of iat applied in #10571 caused performance issues. This PR fixes the performance issues by using a more efficient way to update the values in the dataframe.

GitHub Issue Link (if applicable)

Testing Plan

  • Existing tests should cover this well.
  • Added a benchmark test to keep track of the styler performance.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@lukasmasuch lukasmasuch requested a review from Copilot September 3, 2025 22:44
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 3, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12422/streamlit-1.49.1-py3-none-any.whl
🕹️ Preview app pr-12422.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Copy Markdown
Contributor

@sfc-gh-gwatters sfc-gh-gwatters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current change looks good to me - re-request a review if you decide to optimize further!

We should add a perf test that tracks this scenario.

@lukasmasuch lukasmasuch added security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Sep 8, 2025
@lukasmasuch lukasmasuch requested a review from Copilot September 8, 2025 20:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a performance regression in Pandas styler processing by optimizing data access patterns. The changes replace inefficient .iloc[] accessor usage with faster .iat[] accessor for single-element access and implement batch updates for display value assignments.

Key Changes:

  • Replace .iloc[0] with .iat[0] for single-element access across multiple files
  • Refactor pandas styler display value updates to use batch assignment instead of individual cell updates
  • Optimize color column processing in chart utilities

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/streamlit/elements/map.py Replace .iloc[0] with .iat[0] for faster single-element access in color column validation
lib/streamlit/elements/lib/pandas_styler_utils.py Major refactor to batch display value updates instead of individual .iloc[] assignments
lib/streamlit/elements/lib/built_in_chart_utils.py Replace .iloc[0] with .iat[0] in three locations for date and color column processing

@sfc-gh-lmasuch sfc-gh-lmasuch changed the title [WIP] Fix Pandas styler performance regression Fix Pandas styler performance regression Sep 9, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review September 9, 2025 12:45
@lukasmasuch
Copy link
Copy Markdown
Collaborator Author

@sfc-gh-gwatters I finished up the PR and also applied the suggested performance improvement + added a performance benchmark.

@sfc-gh-gwatters
Copy link
Copy Markdown
Contributor

Looks good. Did you verify that my suggestion was any faster?

@lukasmasuch
Copy link
Copy Markdown
Collaborator Author

Looks good. Did you verify that my suggestion was any faster?

yep, it's consistently faster, gets it down to 1.5s for the example :)

@lukasmasuch lukasmasuch merged commit 09fd745 into develop Sep 10, 2025
35 checks passed
@lukasmasuch lukasmasuch deleted the fix/pandas-styler-performance-regression branch September 10, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants