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

Core: Cleanup: Replace direct calling of dunder methods on objects #4584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mysteryem
Copy link
Contributor

@Mysteryem Mysteryem commented Jan 30, 2025

What is this fixing or adding?

Calling the dunder method has to:

  1. Look up the dunder method for that object/class
  2. Bind a new method instance to the object instance (if the method was defined on the class)
  3. Call the method with its arguments
  4. Run the appropriate operation on the object

Whereas running the appropriate operation on the object from the start skips straight to step 4.

Region.Register.__getitem__ is called a lot without #4583. In that case, generation of 10 template Blasphemous yamls with
--skip_output --seed 1 and progression balancing disabled went from 19.0s to 18.8s (1.3% reduction in generation duration).

From profiling with timeit

        def __getitem__(self, index: int) -> Location:
            return self._list[index]

appears to be about twice as fast as the old code:

        def __getitem__(self, index: int) -> Location:
            return self._list.__getitem__(index)

Besides this, there is not expected to be any noticeable difference in performance, and there is not expected to be any difference in semantics with these changes.

How was this tested?

Ran generations before and after

Calling the dunder method has to:
1. Look up the dunder method for that object/class
2. Bind a new method instance to the object instance
3. Call the method with its arguments
4. Run the appropriate operation on the object

Whereas running the appropriate operation on the object from the start
skips straight to step 4.

Region.Register.__getitem__ is called a lot without ArchipelagoMW#4583. In that case,
generation of 10 template Blasphemous yamls with
`--skip_output --seed 1` and progression balancing disabled went from
19.0s to 18.8s (1.3% reduction in generation duration).

From profiling with `timeit`
```py
        def __getitem__(self, index: int) -> Location:
            return self._list[index]
```
appears to be about twice as fast as the old code:
```py
        def __getitem__(self, index: int) -> Location:
            return self._list.__getitem__(index)
```

Besides this, there is not expected to be any noticeable difference in
performance, and there is not expected to be any difference in semantics
with these changes.
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Jan 30, 2025
@Exempt-Medic Exempt-Medic added the is: enhancement Issues requesting new features or pull requests implementing new features. label Jan 30, 2025
Copy link
Contributor

@silasary silasary left a comment

Choose a reason for hiding this comment

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

Code looks good and change is reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: enhancement Issues requesting new features or pull requests implementing new features. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants