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

Optimized some tests to reduce duration #2274

Merged
merged 3 commits into from Nov 12, 2021

Conversation

christopher-besch
Copy link
Member

@christopher-besch christopher-besch commented Nov 7, 2021

General Problem

Manim testing is very slow and should be optimized.

You can get the slowest 50 test with:

pytest --durations=50

Please run this command and post its output here. You should also state which OS you're using since—as you'll see in a moment—there are huge differences between them.

This is the output on a macbook (from @behackl):

133.24s call     tests/test_scene_rendering/test_cli_flags.py::test_resolution_flag
123.73s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_resolution_flag
72.39s call     tests/test_plugins/test_plugins.py::test_plugin_function_like
43.44s call     tests/test_graphical_units/test_threed.py::test_SurfaceColorscale
40.67s call     tests/test_plugins/test_plugins.py::test_plugin_no_all
39.50s call     tests/test_plugins/test_plugins.py::test_plugin_with_all
26.57s call     tests/test_graphical_units/test_threed.py::test_Arrow3D
25.82s call     tests/test_scene_rendering/opengl/test_caching_related_opengl.py::test_play_skip
19.50s call     tests/test_graphical_units/test_threed.py::test_Line3D
17.56s call     tests/test_scene_rendering/opengl/test_caching_related_opengl.py::test_wait_skip
16.73s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_n_flag
16.61s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_basic_scene_with_default_values
16.01s call     tests/test_graphical_units/test_coordinate_systems.py::test_number_plane_log
15.76s call     tests/test_logging/test_logging.py::test_error_logging
14.90s call     tests/test_graphical_units/test_threed.py::test_Cone
14.87s call     tests/test_scene_rendering/test_cli_flags.py::test_basic_scene_with_default_values
14.42s call     tests/test_scene_rendering/test_caching_related.py::test_play_skip
14.04s call     tests/test_coordinate_system.py::test_NumberPlane
13.47s call     tests/opengl/test_texmobject_opengl.py::test_tex_whitespace_arg
13.35s call     tests/test_scene_rendering/test_cli_flags.py::test_n_flag
12.80s call     tests/opengl/test_texmobject_opengl.py::test_tex_white_space_and_non_whitespace_args
12.45s call     tests/opengl/test_texmobject_opengl.py::test_double_braces_testing[{{ a }} + {{ b }} = {{ c }}-5]
12.23s call     tests/opengl/test_texmobject_opengl.py::test_tex
12.19s call     tests/test_config.py::test_transparent
12.06s call     tests/test_scene_rendering/test_caching_related.py::test_wait_skip
11.80s call     tests/opengl/test_texmobject_opengl.py::test_tex_non_whitespace_arg
11.61s call     tests/test_scene_rendering/test_sections.py::test_no_sections
11.34s call     tests/test_graphical_units/test_axes.py::test_plot
11.23s call     tests/test_graphical_units/test_numbers.py::test_set_value_with_updaters
10.93s call     tests/test_scene_rendering/test_sections.py::test_sections
10.78s call     tests/test_scene_rendering/test_sections.py::test_many_sections
10.13s call     tests/test_graphical_units/test_tables.py::test_Table
10.01s call     tests/test_logging/test_logging.py::test_logging_to_file

This is how it looks like (without the changes of this PR) on my machine—Fedora Linux:

35.93s call     tests/test_scene_rendering/test_cli_flags.py::test_resolution_flag
33.12s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_resolution_flag
16.47s call     tests/test_graphical_units/test_threed.py::test_SurfaceColorscale
10.18s call     tests/test_plugins/test_plugins.py::test_plugin_function_like
9.66s call     tests/test_plugins/test_plugins.py::test_plugin_no_all
8.42s call     tests/test_plugins/test_plugins.py::test_plugin_with_all
7.69s call     tests/test_graphical_units/test_coordinate_systems.py::test_number_plane_log
7.63s call     tests/test_scene_rendering/test_cli_flags.py::test_n_flag
7.57s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_n_flag
6.16s call     tests/test_coordinate_system.py::test_NumberPlane
5.62s call     tests/opengl/test_texmobject_opengl.py::test_double_braces_testing[{{ a }} + {{ b }} = {{ c }}-5]
5.12s call     tests/test_graphical_units/test_tables.py::test_Table
5.10s call     tests/test_scene_rendering/opengl/test_caching_related_opengl.py::test_play_skip
5.09s call     tests/test_texmobject.py::test_tex_whitespace_arg
4.91s call     tests/test_graphical_units/test_coordinate_systems.py::test_number_plane
4.85s call     tests/test_scene_rendering/test_caching_related.py::test_play_skip
4.80s call     tests/opengl/test_texmobject_opengl.py::test_tex_non_whitespace_arg
4.63s call     tests/opengl/test_texmobject_opengl.py::test_tex_white_space_and_non_whitespace_args
4.61s call     tests/test_texmobject.py::test_double_braces_testing[{{ a }} + {{ b }} = {{ c }}-5]
4.55s call     tests/test_graphical_units/test_threed.py::test_Arrow3D
4.50s call     tests/test_number_line.py::test_add_labels
4.45s call     tests/opengl/test_texmobject_opengl.py::test_tex_whitespace_arg
4.28s call     tests/test_scene_rendering/test_sections.py::test_many_sections
4.17s call     tests/opengl/test_number_line_opengl.py::test_add_labels
4.12s call     tests/test_graphical_units/test_threed.py::test_Line3D
4.06s call     tests/test_scene_rendering/test_sections.py::test_skip_animations
4.03s call     tests/test_graphical_units/test_axes.py::test_log_scaling_graph
3.81s call     tests/test_texmobject.py::test_tex_non_whitespace_arg
3.78s call     tests/test_graphical_units/test_axes.py::test_plot_line_graph
3.63s call     tests/test_scene_rendering/opengl/test_caching_related_opengl.py::test_wait_skip
3.55s call     tests/test_graphical_units/test_vector_scene.py::test_vector_to_coords
3.54s call     tests/test_texmobject.py::test_tex_white_space_and_non_whitespace_args
3.41s call     tests/test_scene_rendering/test_cli_flags.py::test_basic_scene_with_default_values
3.38s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_basic_scene_with_default_values
3.27s call     tests/test_scene_rendering/test_caching_related.py::test_wait_skip
3.19s call     tests/test_graphical_units/test_numbers.py::test_set_value_with_updaters
3.00s call     tests/test_scene_rendering/opengl/test_opengl_renderer.py::test_force_window_opengl_render_with_format
2.87s call     tests/test_graphical_units/test_threed.py::test_Cone

To get the time required for the entire test suit, you can use the GNU time tool like this:

\time pytest

Make sure to add the \ as you have to use the GNU time binary and not the shell builtin. You might not need this if you're using a very exotic shell.

You'll receive an output similar to this:

487.73user 269.32system 2:05.35elapsed 603%CPU (0avgtext+0avgdata 802116maxresident)k
0inputs+39152outputs (184major+11896649minor)pagefaults 0swaps

The value you're looking for is xx:yy.zzelapsed. This is the total amount of wall time the user has to wait for the program to finish.

Effects of this PR

This PR is a first attempt at that and is by no means exhaustive. It optimizes a few test while attempting to remove as little testing coverage as possible.
This is my new output:

17.75s call     tests/test_graphical_units/test_threed.py::test_SurfaceColorscale
10.50s call     tests/test_plugins/test_plugins.py::test_plugin_function_like
9.93s call     tests/test_plugins/test_plugins.py::test_plugin_no_all
8.90s call     tests/test_plugins/test_plugins.py::test_plugin_with_all
8.82s call     tests/test_scene_rendering/test_cli_flags.py::test_resolution_flag
7.33s call     tests/test_graphical_units/test_coordinate_systems.py::test_number_plane_log
7.32s call     tests/test_scene_rendering/opengl/test_cli_flags_opengl.py::test_resolution_flag
6.34s call     tests/opengl/test_texmobject_opengl.py::test_double_braces_testing[{{ a }} + {{ b }} = {{ c }}-5]
6.05s call     tests/test_coordinate_system.py::test_NumberPlane
5.46s call     tests/test_texmobject.py::test_tex_whitespace_arg
5.44s call     tests/opengl/test_texmobject_opengl.py::test_tex_non_whitespace_arg
5.21s call     tests/opengl/test_texmobject_opengl.py::test_tex_white_space_and_non_whitespace_rgs
5.11s call     tests/test_scene_rendering/opengl/test_caching_related_opengl.py::test_play_skip
5.07s call     tests/test_graphical_units/test_tables.py::test_Table
5.05s call     tests/test_graphical_units/test_threed.py::test_Arrow3D
4.83s call     tests/test_scene_rendering/test_caching_related.py::test_play_skip
4.79s call     tests/opengl/test_number_line_opengl.py::test_add_labels
4.63s call     tests/opengl/test_texmobject_opengl.py::test_tex_whitespace_arg
4.47s call     tests/test_graphical_units/test_threed.py::test_Line3D
4.46s call     tests/test_texmobject.py::test_double_braces_testing[{{ a }} + {{ b }} = {{ c }}-5]
4.43s call     tests/test_number_line.py::test_add_labels
4.42s call     tests/test_graphical_units/test_axes.py::test_log_scaling_graph
4.22s call     tests/test_scene_rendering/test_sections.py::test_many_sections
4.07s call     tests/test_graphical_units/test_functions.py::test_ImplicitFunction

With this, the tests take a total of 1min and 40sec instead of 2min 5sec without the changes—20% improvement.
This isn't too much, but should be detectable by and just the beginning. It shows how small changes can already improve testing times considerably.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

(1280, 720, ","),
(1920, 1080, "-"),
(2560, 1440, ";"),
# (3840, 2160, ","),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these just left commented out to allow for local testing of these resolutions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I each one of these tests takes ages and do we really need that many different resolutions to be tested?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t think so, think we can just remove the commented out ones ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ups, I misunderstood your first comment. That's exactly why they're commented out and not deleted.
Sorry.

Copy link
Member

@naveen521kk naveen521kk left a comment

Choose a reason for hiding this comment

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

LGTM

@kolibril13 kolibril13 merged commit 24fc316 into ManimCommunity:main Nov 12, 2021
@behackl behackl added the testing Anything related to testing the library label Dec 3, 2021
@behackl behackl changed the title Optimized Tests Optimized some tests to reduce test duration Dec 3, 2021
@behackl behackl changed the title Optimized some tests to reduce test duration Optimized some tests to reduce duration Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants