Skip to content

Make slowness warning for legend(loc="best") more accurate. #14894

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
Jul 26, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 26, 2019

... by actually timing the call duration. Locally I can best-locate
legends even with plots with hundreds of thousands of points basically
instantly, so the old warning was spurious.

The new test is obviously a bit brittle because it depends on how fast
the machine running it is. It's also slower than the test before
(intentionally, because now you actually need a slow-to-place legend
to trigger the warning).

The warning is only emitted after the legend has been placed, but that
seems fine -- if the best-placement is so slow that you ctrl-c the
process, you'll have a traceback anyways. Also, spawning a separate
thread to always emit the warning after exactly 5s will likely just make
things worse performance-wise on average.

The 5s delay is the same as used in font_manager.py.

The original warning went in as #12455.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswell tacaswell modified the milestones: v3.3.0, v3.2.0 Jul 26, 2019
... by actually timing the call duration.  Locally I can best-locate
legends even with plots with hundreds of thousands of points basically
instantly, so the old warning was spurious.

The new test is obviously a bit brittle because it depends on how fast
the machine running it is.  It's also slower than the test before
(intentionally, because now you *actually* need a slow-to-place legend
to trigger the warning).

The warning is only emitted after the legend has been placed, but that
seems fine -- if the best-placement is so slow that you ctrl-c the
process, you'll have a traceback anyways.  Also, spawning a separate
thread to always emit the warning after exactly 5s will likely just make
things worse performance-wise on average.

if self._loc_used_default and time.perf_counter() - start_time > 1:
cbook._warn_external(
'Creating legend with loc="best" can be slow with large '
Copy link
Member

Choose a reason for hiding this comment

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

include the actual run time? Wish we could use the walrus here ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would rather not, as if we do I'm fairly worried the next thing is that someone will ask for the warning threshold to be configurable and whatnot.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough.

@jklymak
Copy link
Member

jklymak commented Jul 26, 2019

seems like a good idea

@jklymak jklymak merged commit 8630eb7 into matplotlib:master Jul 26, 2019
@anntzer anntzer deleted the bestslow branch July 27, 2019 07:16
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