Skip to content

perf: avoid try/except in _hasattr_static #2014

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

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

camriddell
Copy link
Member

@camriddell camriddell commented Feb 14, 2025

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

In #2011 @dangotbanned pointed out that try/except is expensive in Python<3.11 and opted to use a sentinel to avoid those statements.

This codepath is triggered 3 times for every call to from_native so it will be regularly hit multiple times by end users so this could be worth doing.

@camriddell camriddell changed the title perf avoid try/except in _hasattr_static perf: avoid try/except in _hasattr_static Feb 14, 2025
Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Thanks @camriddell and thanks @dangotbanned for monitoring we don't introduce overheads πŸš€

NarwhalDolphinGIF

@FBruzzesi FBruzzesi merged commit 0b79208 into narwhals-dev:main Feb 14, 2025
27 of 30 checks passed
@dangotbanned
Copy link
Member

Thanks @camriddell @FBruzzesi

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.

3 participants