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

Optimize has_intersection func #11378

Closed
wants to merge 2 commits into from

Conversation

artofhuman
Copy link
Contributor

Optimize has_intersection function. It uses in few places, but even so it might be optimized. New version:

  1. Does not allocate new set
  2. A bit of performance speedup
from sqlalchemy import util

import timeit
import functools

a = {1, 2, 3}
b = [2, 3, 4]

t1 = timeit.Timer(functools.partial(util.has_intersection, a, b))
t2 = timeit.Timer(functools.partial(util.has_intersection2, a, b))

print("old", t1.timeit())
print("new", t2.timeit())


old 0.37196154199773446
new 0.29704541599494405

old 0.37331208398973104
new 0.29647241700149607

Description

Checklist

This pull request is:

  • A documentation / typographical / small typing error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@artofhuman artofhuman closed this May 11, 2024
@artofhuman artofhuman reopened this May 11, 2024
Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

Thanks, the change does make sense. Maybe remove the TODO there too

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 258bf1a of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 258bf1a: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5321

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5321 has been merged. Congratulations! :)

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5323 has been merged. Congratulations! :)

sqlalchemy-bot pushed a commit that referenced this pull request May 22, 2024
<!-- Provide a general summary of your proposed changes in the Title field above -->

Optimize `has_intersection` function.  It uses in few places, but even so it might be optimized. New version:
1. Does not allocate new set
2. A bit of performance speedup
```
from sqlalchemy import util

import timeit
import functools

a = {1, 2, 3}
b = [2, 3, 4]

t1 = timeit.Timer(functools.partial(util.has_intersection, a, b))
t2 = timeit.Timer(functools.partial(util.has_intersection2, a, b))

print("old", t1.timeit())
print("new", t2.timeit())

old 0.37196154199773446
new 0.29704541599494405

old 0.37331208398973104
new 0.29647241700149607
```

### Description
<!-- Describe your changes in detail -->

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #11378
Pull-request: #11378
Pull-request-sha: 258bf1a

Change-Id: Ic1ec1448641304eba4751f55f1e3c2b217f7f352
(cherry picked from commit 5b43687)
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.

None yet

3 participants