marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.39k stars 158 forks source link

Code coverage timings bottlenecked by endpoint testing #1598

Closed dmadisetti closed 3 weeks ago

dmadisetti commented 3 weeks ago

Describe the bug

Was wondering if my PR did actually add signficant overhead, so I ran some timings with and without coverage:

top 20 tests w/o coverage:

===================================================================================================== slowest 20 durations ======================================================================================================
4.21s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell[strict_kernel]
4.20s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party[strict_kernel]
4.19s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module[k]
4.18s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function[strict_kernel]
4.18s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function[k]
4.18s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module[strict_kernel]
4.18s call     tests/_server/api/endpoints/test_editing.py::test_format_cell
4.18s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party[k]
4.17s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package[strict_kernel]
4.17s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package[k]
4.16s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function[k]
4.16s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function[strict_kernel]
4.13s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell[k]
3.50s call     tests/_cli/test_cli.py::test_cli_run_shutdown
2.58s call     tests/_server/api/endpoints/test_ws.py::test_file_watcher_calls_reload
2.13s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module_autorun[strict_kernel]
2.12s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module_autorun[k]
2.01s call     tests/_cli/test_cli.py::test_cli_edit_directory
1.62s call     tests/_server/test_sessions.py::test_kernel_manager_interrupt
1.59s call     tests/_cli/test_cli_export.py::TestExportHtmlSmokeTests::test_export_plots_tutorial

w/ coverage + strict pr:

127.88s call     tests/_server/api/endpoints/test_editing.py::test_format_cell
35.95s call     tests/_server/api/endpoints/test_ws.py::test_file_watcher_calls_reload
6.74s call     tests/_server/api/endpoints/test_files.py::test_save_with_header
5.11s call     tests/_server/api/endpoints/test_files.py::test_save_file
4.83s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell[strict_kernel]
4.76s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party[strict_kernel]
4.67s call     tests/_server/api/endpoints/test_files.py::test_save_with_invalid_file
4.62s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell[k]
4.59s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package[k]
4.42s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party[k]
4.40s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package[strict_kernel]
4.38s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module[strict_kernel]
4.35s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function[k]
4.34s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function[strict_kernel]
4.34s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module[k]
4.33s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function[k]
4.32s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function[strict_kernel]
4.29s call     tests/_server/api/endpoints/test_execution.py::TestExecutionRoutes_RunMode::test_set_ui_element_value
4.04s call     tests/_server/api/endpoints/test_export.py::test_export_html_no_code_in_read
4.04s call     tests/_server/api/endpoints/test_export.py::test_other_exports_dont_work_in_read

w/ coverage HEAD:

91.03s call     tests/_server/api/endpoints/test_editing.py::test_format_cell
24.12s call     tests/_server/api/endpoints/test_ws.py::test_file_watcher_calls_reload
9.03s call     tests/_server/api/endpoints/test_files.py::test_save_file
5.74s call     tests/_server/api/endpoints/test_execution.py::TestExecutionRoutes_EditMode::test_instantiate
5.52s call     tests/_server/api/endpoints/test_export.py::test_export_html
4.75s call     tests/_server/api/endpoints/test_files.py::test_save_app_config
4.71s call     tests/_server/api/endpoints/test_export.py::test_other_exports_dont_work_in_read
4.35s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module
4.35s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function
4.33s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package
4.33s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party
4.32s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function
4.24s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell
4.19s call     tests/_server/api/endpoints/test_files.py::test_save_with_invalid_file
4.03s call     tests/_server/api/endpoints/test_export.py::test_export_html_no_code_in_read
4.01s call     tests/_cli/test_cli.py::test_cli_edit_interrupt_twice
3.90s call     tests/_server/api/endpoints/test_resume_session.py::test_refresh_session
3.88s call     tests/_server/api/endpoints/test_editing.py::test_code_autocomplete
3.74s call     tests/_server/api/endpoints/test_config_endpoints.py::test_save_user_config_with_session
3.64s call     tests/_server/api/endpoints/test_execution.py::TestExecutionRoutes_RunMode::test_function_call

Only ran once, so not sure how much different server loads contributed. This still runs faster than GH actions- but tests/_server/api/endpoints/test_editing.py does seems very large. I don't think my PR would add that much overhead?

Environment

Head

Code to reproduce

pytest --durations=20
coverage run --module pytest --durations=20
mscolnick commented 3 weeks ago

test_format_cell reaches into black. i wonder if that is causing the slow load (or thats a red-herring)

akshayka commented 3 weeks ago

We could either only run codecov on merge into main, or just disable codecov entirely. I don't look at the results to be honest.

dmadisetti commented 3 weeks ago

No coverage on HEAD was slower than my strict PR- so I don't think timings are all that reliable

5.50s call     tests/_server/api/endpoints/test_editing.py::test_format_cell
4.24s call     tests/_runtime/reload/test_module_watcher.py::test_reload_third_party
4.16s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_function
4.16s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module
4.16s call     tests/_runtime/reload/test_module_watcher.py::test_reload_function
4.15s call     tests/_runtime/reload/test_module_watcher.py::test_reload_package
4.12s call     tests/_runtime/reload/test_module_watcher.py::test_reload_with_modified_cell
3.50s call     tests/_cli/test_cli.py::test_cli_run_shutdown
2.13s call     tests/_runtime/reload/test_module_watcher.py::test_reload_nested_module_import_module_autorun
2.02s call     tests/_cli/test_cli.py::test_cli_md_edit
2.00s call     tests/_cli/test_cli.py::test_cli_edit_shutdown
1.65s call     tests/_cli/test_cli_export.py::TestExportHtmlSmokeTests::test_export_plots_tutorial
1.61s call     tests/_server/test_sessions.py::test_kernel_manager_interrupt
1.54s call     tests/_runtime/reload/test_autoreload.py::test_reload_module_with_error
1.54s call     tests/_runtime/reload/test_autoreload.py::test_reload_module_with_syntax_error
1.54s call     tests/_runtime/reload/test_autoreload.py::test_reload_function
1.50s call     tests/_cli/test_cli.py::test_cli_run_interrupt_twice
1.50s call     tests/_cli/test_cli.py::test_cli_edit_interrupt_twice
1.32s call     tests/_cli/test_cli_export.py::TestExportHtmlSmokeTests::test_export_dataflow_tutorial
1.28s call     tests/_server/api/endpoints/test_files.py::test_save_file

Looks like codecov is broken rn as well: https://app.codecov.io/github/marimo-team/marimo (at least public view) I definitely think it's a useful metric, but might be burning into your minutes

dmadisetti commented 3 weeks ago

Here's current coverage if you are interested:

---------- coverage: platform linux, python 3.11.9-final-0 -----------
Name                                                      Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------------
marimo/__init__.py                                           39      0      0      0   100%
marimo/__main__.py                                            3      3      2      0     0%
marimo/_ast/__init__.py                                       0      0      0      0   100%
marimo/_ast/app.py                                          264     16    110     14    91%
marimo/_ast/cell.py                                         163     22     66      2    89%
marimo/_ast/codegen.py                                      153     14     87     13    88%
marimo/_ast/compiler.py                                      96      1     40      5    96%
marimo/_ast/errors.py                                         8      0      0      0   100%
marimo/_ast/visitor.py                                      253     21    142      8    90%
marimo/_cli/__init__.py                                       0      0      0      0   100%
marimo/_cli/cli.py                                          146    146    125      0     0%
marimo/_cli/cli_validators.py                                10     10      4      0     0%
marimo/_cli/convert/ipynb.py                                 19      0      6      0   100%
marimo/_cli/convert/markdown.py                             211     24     62      7    88%
marimo/_cli/convert/utils.py                                 19      1      6      1    92%
marimo/_cli/envinfo.py                                       18      4      4      1    68%
marimo/_cli/file_path.py                                    115     35     38      9    69%
marimo/_cli/parse_args.py                                    48      4     26      4    89%
marimo/_cli/print.py                                          7      1      0      0    86%
marimo/_cli/upgrade.py                                       55      9     16      4    76%
marimo/_config/__init__.py                                    0      0      0      0   100%
marimo/_config/config.py                                    118      7     79      7    91%
marimo/_config/manager.py                                    30      0      4      0   100%
marimo/_config/utils.py                                      58     19     18      3    66%
marimo/_data/charts.py                                       87      3     26      2    96%
marimo/_data/get_datasets.py                                 23      3      8      0    90%
marimo/_data/models.py                                       37      0      6      0   100%
marimo/_data/preview_column.py                               68     19     22      7    71%
marimo/_dependencies/dependencies.py                         73     12     56      4    83%
marimo/_islands/island_generator.py                         146     47     50      6    64%
marimo/_loggers.py                                           41     19     20      1    41%
marimo/_messaging/__init__.py                                 0      0      0      0   100%
marimo/_messaging/cell_output.py                             33      2     10      0    95%
marimo/_messaging/completion_option.py                        8      0      2      0   100%
marimo/_messaging/console_output_worker.py                   54     26     24      4    44%
marimo/_messaging/errors.py                                  42      0     16      0   100%
marimo/_messaging/mimetypes.py                                2      0      0      0   100%
marimo/_messaging/ops.py                                    227     16     80      1    94%
marimo/_messaging/streams.py                                168     47     36      5    65%
marimo/_messaging/tracebacks.py                              16      1      2      0    94%
marimo/_messaging/types.py                                   31      3      6      0    92%
marimo/_output/__init__.py                                    0      0      0      0   100%
marimo/_output/builder.py                                    92     10     74     11    87%
marimo/_output/data/data.py                                  52     17     14      5    64%
marimo/_output/doc.py                                        12      5      4      0    56%
marimo/_output/formatters/__init__.py                         0      0      0      0   100%
marimo/_output/formatters/altair_formatters.py               21      0      6      0   100%
marimo/_output/formatters/anywidget_formatters.py            14      5      4      0    61%
marimo/_snippets/data/pandas-2.py                            19      9      8      1    63%
marimo/_snippets/data/pandas-3.py                            24     12     10      1    62%
marimo/_snippets/data/pandas-4.py                            24     12     10      1    62%
marimo/_snippets/data/pandas-5.py                            20     10      8      1    61%
marimo/_snippets/data/pandas-6.py                            22     12      8      1    57%
marimo/_snippets/data/pandas-7.py                            21     11      8      1    59%
marimo/_snippets/data/pandas-8.py                            24     14      8      1    53%
marimo/_snippets/data/pandas-9.py                            20     10      8      1    61%
marimo/_snippets/data/pandas-10.py                           23     11     10      1    64%
marimo/_snippets/data/pandas-11.py                           19      9      8      1    63%
marimo/_snippets/data/pandas-12.py                           22     10     10      1    66%
marimo/_snippets/data/pandas-13.py                           18      8      8      1    65%
marimo/_snippets/data/pandas-14.py                           22     10     10      1    66%
marimo/_snippets/data/pandas-15.py                           22     10     10      1    66%
marimo/_snippets/data/pandas-16.py                           18      8      8      1    65%
marimo/_snippets/data/pandas-17.py                           20     10      8      1    61%
marimo/_snippets/data/pandas-18.py                           20     10      8      1    61%
marimo/_snippets/data/pandas-19.py                           19      9      8      1    63%
marimo/_snippets/data/pandas-20.py                           22     12      8      1    57%
marimo/_snippets/data/pandas-21.py                           22     12      8      1    57%
marimo/_snippets/data/pandas-22.py                           23     11     10      1    64%
marimo/_snippets/data/pandas-23.py                           19      9      8      1    63%
marimo/_snippets/data/pandas-24.py                           29     17     10      1    54%
marimo/_snippets/data/pandas-25.py                           24     12     10      1    62%
marimo/_snippets/data/query-params-0.py                      18      8      8      1    65%
marimo/_snippets/data/query-params-1.py                      27     13     16      1    58%
marimo/_snippets/snippets.py                                 59      2     32      2    96%
marimo/_utils/__init__.py                                     0      0      0      0   100%
marimo/_utils/config/config.py                               40      6     14      6    78%
marimo/_utils/dataclass_to_openapi.py                        67     17     54      8    66%
marimo/_utils/debounce.py                                    15      0      4      0   100%
marimo/_utils/deep_merge.py                                  12      0      8      0   100%
marimo/_utils/deprecated.py                                  11      2      2      0    85%
marimo/_utils/disposable.py                                  15      0      4      0   100%
marimo/_utils/distributor.py                                 43      5     12      2    87%
marimo/_utils/exiting.py                                     11     11      2      0     0%
marimo/_utils/file_watcher.py                                72     25     16      2    69%
marimo/_utils/flatten.py                                     98      5     48      5    93%
marimo/_utils/format_signature.py                            17     15      2      0    11%
marimo/_utils/formatter.py                                   54     23     10      1    53%
marimo/_utils/health.py                                      52     19     16      5    59%
marimo/_utils/log_formatter.py                               62     28     26      5    44%
marimo/_utils/marimo_path.py                                 63     10     26      3    81%
marimo/_utils/parse_dataclass.py                             63      6     48      2    91%
marimo/_utils/paths.py                                       22      4      8      4    73%
marimo/_utils/platform.py                                     5      1      0      0    80%
marimo/_utils/repr.py                                         5      2      2      0    43%
marimo/_utils/rst_to_html.py                                  7      0      2      0   100%
marimo/_utils/signals.py                                      9      4      0      0    56%
marimo/_utils/tmpdir.py                                      24     16      4      1    32%
marimo/_utils/typed_connection.py                            24      8      6      1    70%
marimo/_utils/url.py                                         11      1      4      1    73%
-------------------------------------------------------------------------------------------
TOTAL                                                     14280   3431   5863    563    75%