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

Optimizing ListConfig.__contains__ #530

Merged
merged 3 commits into from
Feb 10, 2021
Merged

Optimizing ListConfig.__contains__ #530

merged 3 commits into from
Feb 10, 2021

Conversation

omry
Copy link
Owner

@omry omry commented Feb 9, 2021

Speedup from 1200x slower than standard list contains to only 68 times slower (~15x).

Closes #529

@omry omry changed the title List in Optimizing ListConfig.__contains__ Feb 9, 2021
Copy link
Collaborator

@odelalleau odelalleau left a comment

Choose a reason for hiding this comment

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

Just not sure about returning False for missing/None

omegaconf/listconfig.py Outdated Show resolved Hide resolved
],
)
def test_list_iter(lst: List[Any], benchmark: Any) -> None:
# Performance is really bad for list config iteration, not sure why.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is that surprising? If you compare to a regular list, ListConfig is doing a lot more stuff to check if any interpolation needs to be resolved, while a regular list can instantly return the reference to the object.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Because it's 500 times slower :).
I don't think it's justified. I tried to profile it a bit and do some blind optimizations but was not able to pinpoint the cause.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok -- actually given the speed-up that you got here, I do agree that it should be possible to iterate faster (x in lst shouldn't be much faster than for y in lst -- at least when iterating through the whole list in both cases)

Speedup from 1200x slower than standard list contains to only 68 times slower :)
Copy link
Collaborator

@odelalleau odelalleau left a comment

Choose a reason for hiding this comment

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

Looks good!

@omry omry merged commit e5cfb4c into master Feb 10, 2021
@omry omry deleted the list_in branch February 10, 2021 00:49
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.

ListConfig.__contains__ significantly slower than list.__contains__
2 participants