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: log completion time if > 1.0 seconds per step #2345

Merged
merged 8 commits into from
Oct 30, 2023
Merged

Conversation

Berserker66
Copy link
Member

What is this fixing or adding?

adds rudimentary performance logging, for longer (async) generations it also gives you a bit of a progress/alive signal.

I consider this the first step of multiple towards having some more useful benchmarking.

How was this tested?

with a few thousand worlds

If this makes graphical changes, please attach screenshots.

worlds/AutoWorld.py Outdated Show resolved Hide resolved
@@ -115,6 +119,10 @@ def call_single(multiworld: "MultiWorld", method_name: str, player: int, *args:
logging.error(message)
raise e
else:
taken = time.perf_counter()-start
if taken > 0.1:
perf_logger.info(f"Took {taken} seconds in {method} for player {player}, "
Copy link
Collaborator

@alwaysintreble alwaysintreble Oct 22, 2023

Choose a reason for hiding this comment

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

Suggested change
perf_logger.info(f"Took {taken} seconds in {method} for player {player}, "
perf_logger.info(f"Took {taken} seconds in {multiworld.worlds[player].__class__.__name__}'s {method.__name__} for player {player}.")

maybe?

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe?

Sounds like you're trying to reinvent method.__qualname__.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be fine with cutting away the ram address, but you're cutting away too much. It also would lose consistency with the error reporting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having something shorter (be it qualname or something similar) would make the lines way shorter and easier to understand.
(It doesn't really have to be consistent with error reporting since it's not an error. It's actually something that a normal user might see during normal operation.)
Also, since all values are gonna be greater than 0.1, I'd suggest formatting the numbers to two decimal places; again, to make it easier for the reader to parse the relevant information.

Copy link
Member Author

Choose a reason for hiding this comment

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

have you tried qualname? Because all it is is "World.set_rules", no matter which world

Copy link
Collaborator

Choose a reason for hiding this comment

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

Strange. I had tested it.
Here's the output I get with {method.__qualname__} (and the threshold removed so that all stages will be printed).
For me it only printed World if it really executed the method of the base class where it was not overridden in the specific world. (And these should never go over the threshold in practice, since they are usually just pass)
(For reference, this was 3.8 on Windows)
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

tested on 3.11.6 and i'm seeing the same output. one interesting thing to note is that it doesn't show the class for methods where it's assigned rather than overridden, since those functions don't belong to the class. Screenshot_36

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's unfortunate. Maybe we have to do something more verbose after all.

@el-u
Copy link
Collaborator

el-u commented Oct 22, 2023

  • Are worlds now expected to do each step in less than 0.1s?
  • Any particular reason why this is not added to call_stage as well?

@ScootyPuffJr1 ScootyPuffJr1 added is: refactor/cleanup Improvements to code/output readability or organizization. affects: core Issues/PRs that touch core and may need additional validation. labels Oct 22, 2023
@Berserker66
Copy link
Member Author

  • Are worlds now expected to do each step in less than 0.1s?
  • Any particular reason why this is not added to call_stage as well?

1
No, but if you do it under that time people are less likely to complain. If you need a lot more than that, people might start to take notice. For example, since I introduced this, I learned that ALTTP create_regions gets longer the more other worlds are present, which is probably fixable. Though I have not yet gotten around to do that, it alerted me to that information.

2
oups

@@ -103,10 +106,23 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Aut
return new_class


def _timed_call(method: Callable, *args: Any, multiworld: "MultiWorld" = None, player: int = None) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _timed_call(method: Callable, *args: Any, multiworld: "MultiWorld" = None, player: int = None) -> Any:
def _timed_call(method: Callable[..., Any], *args: Any,
multiworld: Optional["MultiWorld"] = None, player: Optional[int] = None) -> Any:

Copy link
Collaborator

@el-u el-u left a comment

Choose a reason for hiding this comment

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

Would have preferred a cleaner output (see comment); functionality is fine.

@Berserker66 Berserker66 changed the title Core: log completion time if > 0.1 seconds per step Core: log completion time if > 1.0 seconds per step Oct 25, 2023
Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

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

Lgtm. With >1sec this should be fine on main.

@Berserker66 Berserker66 merged commit d743d10 into main Oct 30, 2023
21 checks passed
@Berserker66 Berserker66 deleted the core_log_perf branch October 30, 2023 03:06
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
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: refactor/cleanup Improvements to code/output readability or organizization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants