Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy-load emoji module to improve performance #8109

Merged
merged 6 commits into from Feb 8, 2024

Conversation

LukasMasuch
Copy link
Collaborator

@LukasMasuch LukasMasuch commented Feb 8, 2024

Describe your changes

The emoji data is the biggest object when running a blank Streamlit app. Compiling the regex is also slightly expensive. However, the emoji data is only required if there is a check for emojis; many apps might not require this. Therefore, this PR makes the emoji module to lazy load only if it is actually required.

This also adds a precheck for emoji checks to make sure that the string even contains non alphanumeric characters before using the more expensive emoji regex.

GitHub Issue Link (if applicable)

Related to #6066

Testing Plan

  • Added e2e test to check that some lazy-loaded modules are not imported in an almost blank Streamlit app.

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 changed the title Lazy-load the emoji data Lazy-load the emoji data to improve performance Feb 8, 2024
@LukasMasuch LukasMasuch changed the title Lazy-load the emoji data to improve performance Lazy-load emoji data to improve performance Feb 8, 2024
@LukasMasuch LukasMasuch marked this pull request as ready for review February 8, 2024 13:27
@LukasMasuch LukasMasuch changed the title Lazy-load emoji data to improve performance Lazy-load emoji module to improve performance Feb 8, 2024
@LukasMasuch LukasMasuch merged commit 7c5b6a0 into develop Feb 8, 2024
38 checks passed
@@ -40,14 +36,29 @@ def clean_text(text: "SupportsStr") -> str:
return textwrap.dedent(str(text)).strip()


def _contains_special_chars(text: str) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@LukasMasuch If I understand correctly this code, this method could be replaced with python built-in
str.isalnum method

zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
## Describe your changes

The emoji data is the biggest object when running a blank Streamlit app.
Compiling the regex is also slightly expensive. However, the emoji data
is only required if there is a check for emojis; many apps might not
require this. Therefore, this PR makes the emoji module to lazy load
only if it is actually required.

This also adds a precheck for emoji checks to make sure that the string
even contains non alphanumeric characters before using the more
expensive emoji regex.

## GitHub Issue Link (if applicable)

Related to streamlit#6066

## Testing Plan

- Added e2e test to check that some lazy-loaded modules are not imported
in an almost blank Streamlit app.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants