{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"button": false,
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Debugging Performance Issues\n",
"\n",
"Most chapters of this book deal with _functional_ issues – that is, issues related to the _functionality_ (or its absence) of the code in question. However, debugging can also involve _nonfunctional_ issues, however – performance, usability, reliability, and more. In this chapter, we give a short introduction on how to debug such nonfunctional issues, notably _performance_ issues."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:33:22.427342Z",
"iopub.status.busy": "2024-01-17T21:33:22.426765Z",
"iopub.status.idle": "2024-01-17T21:33:22.494274Z",
"shell.execute_reply": "2024-01-17T21:33:22.493945Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from bookutils import YouTubeVideo\n",
"YouTubeVideo(\"0tMeB9G0uUI\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"**Prerequisites**\n",
"\n",
"* This chapter leverages visualization capabilities from [the chapter on statistical debugging](StatisticalDebugger.ipynb).\n",
"* We also show how to debug nonfunctional issues using [delta debugging](DeltaDebugger.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"button": false,
"execution": {
"iopub.execute_input": "2024-01-17T21:33:22.515763Z",
"iopub.status.busy": "2024-01-17T21:33:22.515585Z",
"iopub.status.idle": "2024-01-17T21:33:22.517670Z",
"shell.execute_reply": "2024-01-17T21:33:22.517357Z"
},
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import bookutils.setup"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:33:22.519369Z",
"iopub.status.busy": "2024-01-17T21:33:22.519254Z",
"iopub.status.idle": "2024-01-17T21:33:23.155404Z",
"shell.execute_reply": "2024-01-17T21:33:23.155086Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import StatisticalDebugger\n",
"import DeltaDebugger"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"## Synopsis\n",
"\n",
"\n",
"To [use the code provided in this chapter](Importing.ipynb), write\n",
"\n",
"```python\n",
">>> from debuggingbook.PerformanceDebugger import \n",
"```\n",
"\n",
"and then make use of the following features.\n",
"\n",
"\n",
"This chapter provides a class `PerformanceDebugger` that allows measuring and visualizing the time taken per line in a function.\n",
"\n",
"```python\n",
">>> with PerformanceDebugger(TimeCollector) as debugger:\n",
">>> for i in range(100):\n",
">>> s = remove_html_markup('foo')\n",
"```\n",
"The distribution of executed time within each function can be obtained by printing out the debugger:\n",
"\n",
"```python\n",
">>> print(debugger)\n",
" 238 2% def remove_html_markup(s): # type: ignore\n",
" 239 2% tag = False\n",
" 240 1% quote = False\n",
" 241 1% out = \"\"\n",
" 242 0%\n",
" 243 17% for c in s:\n",
" 244 15% assert tag or not quote\n",
" 245 0%\n",
" 246 15% if c == '<' and not quote:\n",
" 247 3% tag = True\n",
" 248 12% elif c == '>' and not quote:\n",
" 249 3% tag = False\n",
" 250 9% elif (c == '\"' or c == \"'\") and tag:\n",
" 251 0% quote = not quote\n",
" 252 9% elif not tag:\n",
" 253 4% out = out + c\n",
" 254 0%\n",
" 255 3% return out\n",
"\n",
"\n",
"```\n",
"The sum of all percentages in a function should always be 100%.\n",
"\n",
"These percentages can also be visualized, where darker shades represent higher percentage values:\n",
"\n",
"```python\n",
">>> debugger\n",
"```\n",
"
238 def remove_html_markup(s): # type: ignore
\n",
"
239 tag = False
\n",
"
240 quote = False
\n",
"
241 out = ""
\n",
"
242
\n",
"
243 for c in s:
\n",
"
244 assert tag or not quote
\n",
"
245
\n",
"
246 if c == '<' and not quote:
\n",
"
247 tag = True
\n",
"
248 elif c == '>' and not quote:
\n",
"
249 tag = False
\n",
"
250 elif (c == '"' or c == "'") and tag:
\n",
"
251 quote = not quote
\n",
"
252 elif not tag:
\n",
"
253 out = out + c
\n",
"
254
\n",
"
255 return out
\n",
"\n",
"\n",
"The abstract `MetricCollector` class allows subclassing to build more collectors, such as `HitCollector`.\n",
"\n",
"![](PICS/PerformanceDebugger-synopsis-1.svg)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Measuring Performance\n",
"\n",
"The solution to debugging performance issues fits in two simple rules:\n",
"\n",
"1. _Measure_ performance\n",
"2. _Break down_ how individual parts of your code contribute to performance.\n",
"\n",
"The first part, actually _measuring_ performance, is key here. Developers often take elaborated guesses on which aspects of their code impact performance, and think about all possible ways to optimize their code – and at the same time, making it harder to understand, harder to evolve, and harder to maintain. In most cases, such guesses are wrong. Instead, _measure_ performance of your program, _identify_ the very few parts that may need to get improved, and again _measure_ the impact of your changes."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Almost all programming languages offer a way to measure performance and breaking it down to individual parts of the code – a means also known as *profiling*. Profiling works by measuring the execution time for each function (or even more fine-grained location) in your program. This can be achieved by\n",
"\n",
"1. _Instrumenting_ or _tracing_ code such that the current time at entry and exit of each function (or line), thus determining the time spent. In Python, this is achieved by profilers like [profile or cProfile](https://docs.python.org/3/library/profile.html)\n",
"\n",
"2. _Sampling_ the current function call stack at regular intervals, and thus assessing which functions are most active (= take the most time) during execution. For Python, the [scalene](https://github.com/plasma-umass/scalene) profiler works this way.\n",
"\n",
"Pretty much all programming languages support profiling, either through measuring, sampling, or both. As a rule of thumb, _interpreted_ languages more frequently support measuring (as it is easy to implement in an interpreter), while _compiled_ languages more frequently support sampling (because instrumentation requires recompilation). Python is lucky to support both methods."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Tracing Execution Profiles\n",
"\n",
"Let us illustrate profiling in a simple example. The `ChangeCounter` class (which we will encounter in the [chapter on mining version histories](ChangeCounter.ipynb)) reads in a version history from a git repository. Yet, it takes more than a minute to read in the debugging book change history:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:33:23.157407Z",
"iopub.status.busy": "2024-01-17T21:33:23.157289Z",
"iopub.status.idle": "2024-01-17T21:33:24.551472Z",
"shell.execute_reply": "2024-01-17T21:33:24.551114Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"from ChangeCounter import ChangeCounter, debuggingbook_change_counter # minor dependency"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:33:24.553591Z",
"iopub.status.busy": "2024-01-17T21:33:24.553401Z",
"iopub.status.idle": "2024-01-17T21:33:24.555248Z",
"shell.execute_reply": "2024-01-17T21:33:24.554962Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import Timer"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:33:24.556884Z",
"iopub.status.busy": "2024-01-17T21:33:24.556767Z",
"iopub.status.idle": "2024-01-17T21:35:36.599076Z",
"shell.execute_reply": "2024-01-17T21:35:36.598064Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"with Timer.Timer() as t:\n",
" change_counter = debuggingbook_change_counter(ChangeCounter)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:35:36.612715Z",
"iopub.status.busy": "2024-01-17T21:35:36.612562Z",
"iopub.status.idle": "2024-01-17T21:35:36.615215Z",
"shell.execute_reply": "2024-01-17T21:35:36.614948Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"132.0370005420009"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t.elapsed_time()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"The Python `profile` and `cProfile` modules offer a simple way to identify the most time-consuming functions. They are invoked using the `run()` function, whose argument is the command to be profiled. The output reports, for each function encountered:\n",
"\n",
"* How often it was called (`ncalls` column)\n",
"* How much time was spent in the given function, _excluding_ time spent in calls to sub-functions (`tottime` column)\n",
"* The fraction of `tottime` / `ncalls` (first `percall` column)\n",
"* How much time was spent in the given function, _including_ time spent in calls to sub-functions (`cumtime` column)\n",
"* The fraction of `cumtime` / `percall` (second `percall` column)\n",
"\n",
"Let us have a look at the profile we obtain:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:35:36.621751Z",
"iopub.status.busy": "2024-01-17T21:35:36.621498Z",
"iopub.status.idle": "2024-01-17T21:35:36.623627Z",
"shell.execute_reply": "2024-01-17T21:35:36.623287Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import cProfile"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:35:36.625918Z",
"iopub.status.busy": "2024-01-17T21:35:36.625681Z",
"iopub.status.idle": "2024-01-17T21:38:37.912116Z",
"shell.execute_reply": "2024-01-17T21:38:37.911565Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 20748934 function calls (20601589 primitive calls) in 181.004 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 181.004 181.004 {built-in method builtins.exec}\n",
" 1 0.000 0.000 181.004 181.004 :1()\n",
" 1 0.000 0.000 181.004 181.004 ChangeCounter.ipynb:168(debuggingbook_change_counter)\n",
" 1 0.001 0.001 181.004 181.004 ChangeCounter.ipynb:51(__init__)\n",
" 1 0.964 0.964 181.003 181.003 ChangeCounter.ipynb:88(mine)\n",
" 1189 0.020 0.000 179.804 0.151 ChangeCounter.ipynb:102(mine_commit)\n",
" 1189 0.039 0.000 179.618 0.151 commit.py:680(modified_files)\n",
" 1189 0.020 0.000 179.578 0.151 commit.py:696(_get_modified_files)\n",
" 1139 0.194 0.000 153.347 0.135 diff.py:95(diff)\n",
" 1184 0.092 0.000 83.934 0.071 cmd.py:1114(_call_process)\n",
" 1184 0.107 0.000 83.826 0.071 cmd.py:726(execute)\n",
" 1184 0.194 0.000 83.393 0.070 subprocess.py:753(__init__)\n",
" 1184 0.233 0.000 83.158 0.070 subprocess.py:1682(_execute_child)\n",
" 1184 80.473 0.068 80.473 0.068 {built-in method _posixsubprocess.fork_exec}\n",
" 1140 0.062 0.000 80.071 0.070 cmd.py:638()\n",
" 1139 15.526 0.014 73.091 0.064 diff.py:445(_index_from_patch_format)\n",
" 1139 0.077 0.000 45.108 0.040 cmd.py:71(handle_process_output)\n",
" 11490 44.568 0.004 44.568 0.004 {method 'acquire' of '_thread.lock' objects}\n",
" 2280 0.007 0.000 44.500 0.020 threading.py:1057(join)\n",
" 2280 0.012 0.000 44.491 0.020 threading.py:1095(_wait_for_tstate_lock)\n",
" 1189 0.047 0.000 26.183 0.022 commit.py:730(_parse_diff)\n",
" 24586 0.027 0.000 25.195 0.001 commit.py:759(_get_undecoded_content)\n",
" 81634 0.085 0.000 20.105 0.000 cmd.py:528(read)\n",
" 68962 0.021 0.000 20.080 0.000 base.py:137(read)\n",
" 163246 20.013 0.000 20.013 0.000 {method 'read' of '_io.BufferedReader' objects}\n",
" 12293 0.091 0.000 11.608 0.001 diff.py:290(__init__)\n",
" 11483 0.011 0.000 11.305 0.001 base.py:363(submodules)\n",
" 11483 0.038 0.000 11.294 0.001 util.py:1092(list_items)\n",
"24150/24147 0.029 0.000 11.242 0.000 {method 'extend' of 'list' objects}\n",
" 34449 0.132 0.000 11.213 0.000 base.py:1228(iter_items)\n",
" 81634 0.117 0.000 8.025 0.000 db.py:46(stream)\n",
" 81634 0.185 0.000 7.830 0.000 cmd.py:1263(stream_object_data)\n",
" 23030 0.019 0.000 5.213 0.000 base.py:129(data_stream)\n",
" 127566 0.413 0.000 5.040 0.000 cmd.py:1235(__get_object_header)\n",
" 59743 0.051 0.000 4.415 0.000 util.py:248(__getattr__)\n",
" 127566 0.028 0.000 3.972 0.000 cmd.py:1221(_get_persistent_cmd)\n",
" 210571 3.882 0.000 3.885 0.000 {method 'readline' of '_io.BufferedReader' objects}\n",
"80381/22966 0.047 0.000 3.589 0.000 tree.py:347(__getitem__)\n",
"80381/22966 0.158 0.000 3.565 0.000 tree.py:245(join)\n",
" 34449 0.029 0.000 3.335 0.000 base.py:527(commit)\n",
" 45932 0.049 0.000 3.158 0.000 tree.py:224(_set_cache_)\n",
" 34449 0.018 0.000 2.924 0.000 symbolic.py:212(_get_commit)\n",
" 34449 0.033 0.000 2.906 0.000 symbolic.py:203(_get_object)\n",
" 45932 0.031 0.000 2.103 0.000 symbolic.py:143(dereference_recursive)\n",
" 91865 0.070 0.000 2.072 0.000 symbolic.py:196(_get_ref_info)\n",
" 91865 0.222 0.000 2.003 0.000 symbolic.py:156(_get_ref_info_helper)\n",
" 11483 0.051 0.000 1.998 0.000 base.py:196(_config_parser)\n",
" 1184 1.931 0.002 1.931 0.002 {built-in method posix.read}\n",
" 45932 0.100 0.000 1.926 0.000 base.py:75(new_from_sha)\n",
" 45932 0.072 0.000 1.587 0.000 db.py:42(info)\n",
" 45932 0.034 0.000 1.469 0.000 cmd.py:1243(get_object_header)\n",
" 11483 0.054 0.000 1.272 0.000 fun.py:191(rev_parse)\n",
" 11483 0.039 0.000 1.209 0.000 fun.py:121(name_to_object)\n",
" 13811 0.032 0.000 1.196 0.000 commit.py:196(_set_cache_)\n",
" 106102 1.125 0.000 1.176 0.000 {built-in method io.open}\n",
" 11483 0.027 0.000 0.985 0.000 util.py:72(__init__)\n",
" 11569 0.040 0.000 0.965 0.000 config.py:281(__init__)\n",
"92126/80468 0.064 0.000 0.964 0.000 config.py:104(assure_data_present)\n",
" 11569 0.049 0.000 0.920 0.000 configparser.py:601(__init__)\n",
" 45932 0.674 0.000 0.888 0.000 fun.py:59(tree_entries_from_data)\n",
" 1139 0.770 0.001 0.770 0.001 {method 'join' of 'bytes' objects}\n",
" 1028421 0.756 0.000 0.756 0.000 {method 'decode' of 'bytes' objects}\n",
" 11569 0.178 0.000 0.730 0.000 configparser.py:1321(__init__)\n",
"92126/80557 0.068 0.000 0.686 0.000 config.py:543(read)\n",
" 12293 0.003 0.000 0.661 0.000 commit.py:749(_get_decoded_str)\n",
" 11569 0.218 0.000 0.432 0.000 config.py:391(_read)\n",
" 12672 0.093 0.000 0.377 0.000 commit.py:525(_deserialize)\n",
" 11569 0.374 0.000 0.374 0.000 {built-in method builtins.dir}\n",
" 92033 0.269 0.000 0.333 0.000 {method 'read' of '_io.TextIOWrapper' objects}\n",
" 1184 0.091 0.000 0.270 0.000 subprocess.py:1222(_close_pipe_fds)\n",
" 1586437 0.255 0.000 0.255 0.000 {method 'match' of 're.Pattern' objects}\n",
" 127566 0.246 0.000 0.247 0.000 {method 'flush' of '_io.BufferedWriter' objects}\n",
" 13482 0.005 0.000 0.245 0.000 commit.py:587(committer_date)\n",
" 13482 0.006 0.000 0.240 0.000 commit.py:209(committed_datetime)\n",
" 12293 0.036 0.000 0.239 0.000 commit.py:155(__init__)\n",
" 1190 0.001 0.000 0.234 0.000 repository.py:207(traverse_commits)\n",
" 135329 0.147 0.000 0.223 0.000 posixpath.py:71(join)\n",
" 2280 0.101 0.000 0.219 0.000 threading.py:820(__init__)\n",
" 2280 0.013 0.000 0.211 0.000 threading.py:909(start)\n",
" 1184 0.038 0.000 0.209 0.000 os.py:711(copy)\n",
" 127566 0.142 0.000 0.206 0.000 cmd.py:1207(_prepare_ref)\n",
" 23290 0.018 0.000 0.203 0.000 pathlib.py:955(__new__)\n",
" 1193 0.024 0.000 0.188 0.000 repository.py:246(_iter_commits)\n",
" 46017 0.051 0.000 0.187 0.000 configparser.py:766(get)\n",
" 401905 0.112 0.000 0.187 0.000 compat.py:49(safe_decode)\n",
" 23292 0.014 0.000 0.186 0.000 pathlib.py:587(_from_parts)\n",
" 801100 0.120 0.000 0.181 0.000 cmd.py:466(__getattr__)\n",
" 127566 0.131 0.000 0.177 0.000 cmd.py:1185(_parse_object_header)\n",
" 23292 0.045 0.000 0.169 0.000 pathlib.py:567(_parse_args)\n",
" 93117 0.093 0.000 0.166 0.000 base.py:153(__init__)\n",
" 25344 0.034 0.000 0.152 0.000 util.py:268(parse_actor_and_date)\n",
" 103605 0.141 0.000 0.141 0.000 {method '__exit__' of '_io._IOBase' objects}\n",
" 47121 0.030 0.000 0.140 0.000 tree.py:214(__init__)\n",
" 152960 0.106 0.000 0.138 0.000 base.py:50(__init__)\n",
" 45932 0.073 0.000 0.138 0.000 util.py:85(get_object_type_by_name)\n",
" 2412 0.053 0.000 0.138 0.000 contextlib.py:496(callback)\n",
" 23288 0.095 0.000 0.135 0.000 util.py:69(mode_str_to_int)\n",
" 11569 0.071 0.000 0.132 0.000 configparser.py:1244(__init__)\n",
"1046806/1046805 0.125 0.000 0.126 0.000 {built-in method builtins.getattr}\n",
" 2281 0.008 0.000 0.126 0.000 threading.py:582(wait)\n",
" 23292 0.061 0.000 0.116 0.000 pathlib.py:56(parse_parts)\n",
" 2282 0.012 0.000 0.112 0.000 threading.py:288(wait)\n",
" 59843 0.043 0.000 0.108 0.000 commit.py:84(__init__)\n",
" 1800341 0.102 0.000 0.105 0.000 {built-in method builtins.isinstance}\n",
" 116117 0.047 0.000 0.105 0.000 os.py:674(__getitem__)\n",
" 268768 0.063 0.000 0.103 0.000 os.py:804(fsencode)\n",
" 13482 0.017 0.000 0.094 0.000 util.py:167(from_timestamp)\n",
" 1140 0.010 0.000 0.087 0.000 util.py:383(finalize_process)\n",
" 22966 0.012 0.000 0.083 0.000 base.py:335(index)\n",
" 1184 0.013 0.000 0.082 0.000 util.py:412(remove_password_if_present)\n",
" 80465 0.061 0.000 0.082 0.000 util.py:163(join_path)\n",
" 2279 0.053 0.000 0.082 0.000 cmd.py:470(wait)\n",
" 46017 0.042 0.000 0.077 0.000 configparser.py:1143(_unify_values)\n",
" 74063 0.074 0.000 0.075 0.000 {method 'search' of 're.Pattern' objects}\n",
" 2412 0.065 0.000 0.073 0.000 contextlib.py:514(_push_exit_callback)\n",
" 2280 0.072 0.000 0.072 0.000 {built-in method _thread.start_new_thread}\n",
" 22966 0.017 0.000 0.071 0.000 base.py:117(__init__)\n",
" 1184 0.018 0.000 0.065 0.000 os.py:619(get_exec_path)\n",
" 92033 0.047 0.000 0.064 0.000 codecs.py:319(decode)\n",
" 25344 0.021 0.000 0.063 0.000 util.py:665(_from_string)\n",
" 117216 0.013 0.000 0.062 0.000 _collections_abc.py:877(__iter__)\n",
" 31968 0.013 0.000 0.060 0.000 subprocess.py:1770()\n",
" 11572 0.011 0.000 0.060 0.000 config.py:489(_has_includes)\n",
" 11528 0.032 0.000 0.058 0.000 parse.py:437(urlsplit)\n",
" 22966 0.014 0.000 0.054 0.000 base.py:157(_index_path)\n",
" 46017 0.033 0.000 0.052 0.000 __init__.py:976(__getitem__)\n",
" 24586 0.009 0.000 0.052 0.000 diff.py:432(_pick_best_path)\n",
" 22966 0.017 0.000 0.051 0.000 base.py:114(__init__)\n",
" 92033 0.034 0.000 0.051 0.000 codecs.py:309(__init__)\n",
" 117216 0.028 0.000 0.050 0.000 os.py:697(__iter__)\n",
" 727119 0.050 0.000 0.050 0.000 {built-in method builtins.len}\n",
" 1222 0.010 0.000 0.048 0.000 cmd.py:463(__del__)\n",
" 91865 0.035 0.000 0.048 0.000 symbolic.py:43(_git_dir)\n",
" 115046 0.039 0.000 0.048 0.000 config.py:192(__getitem__)\n",
" 512583 0.048 0.000 0.048 0.000 {method 'encode' of 'str' objects}\n",
" 2320 0.006 0.000 0.048 0.000 subprocess.py:1199(wait)\n",
" 11569 0.017 0.000 0.048 0.000 config.py:492(_included_paths)\n",
" 210948 0.046 0.000 0.047 0.000 {method 'split' of 'str' objects}\n",
" 232064 0.026 0.000 0.045 0.000 os.py:758(decode)\n",
" 2280 0.044 0.000 0.045 0.000 threading.py:1294(_make_invoke_excepthook)\n",
" 12293 0.006 0.000 0.043 0.000 ChangeCounter.ipynb:112(include)\n",
" 24586 0.028 0.000 0.043 0.000 diff.py:54(decode_path)\n",
" 2320 0.011 0.000 0.042 0.000 subprocess.py:1906(_wait)\n",
" 34450 0.016 0.000 0.042 0.000 base.py:342(head)\n",
" 13482 0.039 0.000 0.042 0.000 {built-in method fromtimestamp}\n",
" 23050 0.012 0.000 0.040 0.000 util.py:200(join_path_native)\n",
" 84 0.000 0.000 0.039 0.000 util.py:98(wrapper)\n",
" 84 0.000 0.000 0.039 0.000 base.py:1103(module)\n",
" 85 0.002 0.000 0.039 0.000 base.py:108(__init__)\n",
" 81634 0.025 0.000 0.038 0.000 base.py:128(__new__)\n",
" 289610 0.038 0.000 0.038 0.000 {method 'endswith' of 'str' objects}\n",
" 2281 0.007 0.000 0.038 0.000 threading.py:538(__init__)\n",
" 236612 0.037 0.000 0.037 0.000 {method 'startswith' of 'str' objects}\n",
" 81440 0.037 0.000 0.037 0.000 config.py:180(__setitem__)\n",
" 12293 0.008 0.000 0.037 0.000 ChangeCounter.ipynb:176(filter)\n",
" 710892 0.037 0.000 0.037 0.000 {method 'append' of 'list' objects}\n",
" 88780 0.035 0.000 0.035 0.000 {built-in method sys.intern}\n",
" 116117 0.022 0.000 0.035 0.000 os.py:754(encode)\n",
" 138292 0.022 0.000 0.034 0.000 posixpath.py:41(_get_sep)\n",
" 139728 0.034 0.000 0.034 0.000 typing.py:305(inner)\n",
" 1222 0.006 0.000 0.032 0.000 cmd.py:421(_terminate)\n",
" 45933 0.024 0.000 0.032 0.000 :1053(_handle_fromlist)\n",
" 22966 0.026 0.000 0.032 0.000 symbolic.py:439(to_full_path)\n",
" 45933 0.024 0.000 0.032 0.000 :404(parent)\n",
" 1190 0.000 0.000 0.032 0.000 git.py:110(get_list_commits)\n",
" 152960 0.030 0.000 0.030 0.000 {method 'split' of 'bytes' objects}\n",
" 1181 0.004 0.000 0.030 0.000 subprocess.py:1893(_try_wait)\n",
" 12293 0.015 0.000 0.029 0.000 commit.py:923(_from_change_to_modification_type)\n",
" 30081 0.009 0.000 0.028 0.000 commit.py:243(new_path)\n",
" 22966 0.019 0.000 0.028 0.000 configparser.py:878(has_option)\n",
" 223111 0.028 0.000 0.028 0.000 {built-in method binascii.a2b_hex}\n",
" 164381 0.027 0.000 0.027 0.000 {built-in method __new__ of type object at 0x100b670a0}\n",
" 1184 0.027 0.000 0.027 0.000 cmd.py:416(__init__)\n",
" 81634 0.026 0.000 0.026 0.000 cmd.py:517(__init__)\n",
" 127698 0.026 0.000 0.026 0.000 {method 'write' of '_io.BufferedWriter' objects}\n",
" 34451 0.020 0.000 0.026 0.000 head.py:38(__init__)\n",
" 1263 0.025 0.000 0.025 0.000 {built-in method posix.waitpid}\n",
" 42 0.000 0.000 0.025 0.001 base.py:1121(module_exists)\n",
" 82 0.000 0.000 0.024 0.000 cmd.py:1273(clear_cache)\n",
" 45932 0.015 0.000 0.024 0.000 base.py:35(__new__)\n",
" 82809 0.023 0.000 0.023 0.000 typing.py:1408(_no_init_or_replace_init)\n",
" 13482 0.020 0.000 0.023 0.000 {method 'astimezone' of 'datetime.datetime' objects}\n",
" 2286 0.022 0.000 0.023 0.000 threading.py:236(__init__)\n",
" 128091 0.021 0.000 0.021 0.000 {method 'group' of 're.Match' objects}\n",
" 1184 0.021 0.000 0.021 0.000 warnings.py:458(__enter__)\n",
" 46956 0.020 0.000 0.021 0.000 config.py:183(add)\n",
" 431972 0.021 0.000 0.021 0.000 {built-in method posix.fspath}\n",
" 1184 0.012 0.000 0.020 0.000 contextlib.py:533(__exit__)\n",
" 29600 0.012 0.000 0.019 0.000 pathlib.py:619(__str__)\n",
" 132372 0.019 0.000 0.019 0.000 {built-in method binascii.b2a_hex}\n",
" 1 0.000 0.000 0.019 0.019 base.py:560(iter_commits)\n",
" 1 0.000 0.000 0.019 0.019 commit.py:246(iter_items)\n",
" 1184 0.019 0.000 0.019 0.000 contextlib.py:452(__init__)\n",
" 245997 0.018 0.000 0.018 0.000 {method 'strip' of 'str' objects}\n",
" 25344 0.018 0.000 0.018 0.000 util.py:110(utctz_to_altz)\n",
" 1184 0.006 0.000 0.018 0.000 subprocess.py:1583(_get_handles)\n",
" 127201 0.017 0.000 0.017 0.000 {method 'startswith' of 'bytes' objects}\n",
" 92033 0.017 0.000 0.017 0.000 {built-in method _codecs.utf_8_decode}\n",
" 81634 0.016 0.000 0.016 0.000 base.py:132(__init__)\n",
" 92033 0.016 0.000 0.016 0.000 codecs.py:260(__init__)\n",
" 80 0.000 0.000 0.016 0.000 base.py:240(__del__)\n",
" 80 0.001 0.000 0.016 0.000 base.py:246(close)\n",
" 62981 0.016 0.000 0.016 0.000 {method 'groups' of 're.Match' objects}\n",
" 116533 0.013 0.000 0.016 0.000 {built-in method builtins.hasattr}\n",
" 33692 0.011 0.000 0.015 0.000 base.py:105(__ne__)\n",
" 23052 0.013 0.000 0.015 0.000 configparser.py:644(sections)\n",
" 139157 0.015 0.000 0.015 0.000 {method 'rstrip' of 'str' objects}\n",
" 3596 0.015 0.000 0.015 0.000 {built-in method posix.pipe}\n",
" 81634 0.014 0.000 0.014 0.000 cmd.py:604(__del__)\n",
" 46017 0.014 0.000 0.014 0.000 __init__.py:966(__init__)\n",
" 4781 0.013 0.000 0.013 0.000 {built-in method posix.close}\n",
" 46017 0.013 0.000 0.013 0.000 base.py:296(common_dir)\n",
" 19880 0.013 0.000 0.013 0.000 {method 'get' of 'dict' objects}\n",
" 57889 0.013 0.000 0.013 0.000 {built-in method builtins.setattr}\n",
" 13482 0.013 0.000 0.013 0.000 util.py:147(__init__)\n",
" 2280 0.009 0.000 0.013 0.000 _weakrefset.py:86(add)\n",
" 2 0.000 0.000 0.012 0.006 {built-in method builtins.next}\n",
" 2 0.000 0.000 0.012 0.006 repository.py:173(_prep_repo)\n",
" 22966 0.010 0.000 0.012 0.000 util.py:34(sm_name)\n",
" 1184 0.012 0.000 0.012 0.000 warnings.py:437(__init__)\n",
" 1190 0.001 0.000 0.012 0.000 commit.py:318(_iter_from_process_or_stream)\n",
" 2412 0.011 0.000 0.011 0.000 contextlib.py:446(_create_cb_wrapper)\n",
"10299/1184 0.007 0.000 0.011 0.000 cmd.py:1069(__unpack_args)\n",
" 12293 0.009 0.000 0.011 0.000 commit.py:549(committer)\n",
" 338/170 0.001 0.000 0.011 0.000 fun.py:85(find_submodule_git_dir)\n",
" 23603 0.008 0.000 0.011 0.000 diff.py:403(a_path)\n",
" 177819 0.011 0.000 0.011 0.000 typing.py:1715(cast)\n",
" 4560 0.011 0.000 0.011 0.000 threading.py:1176(daemon)\n",
" 756 0.002 0.000 0.010 0.000 ChangeCounter.ipynb:121(update_stats)\n",
" 45932 0.010 0.000 0.010 0.000 base.py:38(__init__)\n",
" 11528 0.004 0.000 0.010 0.000 parse.py:155(password)\n",
" 5750 0.010 0.000 0.010 0.000 {built-in method _thread.allocate_lock}\n",
" 1184 0.005 0.000 0.009 0.000 warnings.py:165(simplefilter)\n",
" 11483 0.008 0.000 0.009 0.000 util.py:970(__new__)\n",
" 57461 0.009 0.000 0.009 0.000 {method 'rpartition' of 'str' objects}\n",
" 2278 0.007 0.000 0.009 0.000 threading.py:1191(daemon)\n",
" 1 0.000 0.000 0.009 0.009 contextlib.py:139(__exit__)\n",
" 2 0.000 0.000 0.009 0.004 git.py:77(clear)\n",
" 115178 0.009 0.000 0.009 0.000 {function _OMD.__getitem__ at 0x12743a320}\n",
" 1139 0.009 0.000 0.009 0.000 {method 'finditer' of 're.Pattern' objects}\n",
" 24013 0.006 0.000 0.008 0.000 diff.py:407(b_path)\n",
" 115940 0.008 0.000 0.008 0.000 config.py:387(optionxform)\n",
" 10755 0.005 0.000 0.008 0.000 diff.py:426(renamed_file)\n",
" 11809 0.005 0.000 0.008 0.000 pathlib.py:606(_format_parsed_parts)\n",
" 4560 0.007 0.000 0.008 0.000 threading.py:1423(current_thread)\n",
" 85 0.000 0.000 0.007 0.000 base.py:488(config_reader)\n",
" 11334 0.003 0.000 0.007 0.000 config.py:352(__del__)\n",
" 4694 0.007 0.000 0.007 0.000 {method 'append' of 'collections.deque' objects}\n",
" 2278 0.007 0.000 0.007 0.000 threading.py:775(_newname)\n",
" 1189 0.003 0.000 0.007 0.000 conf.py:257(is_commit_filtered)\n",
" 1184 0.007 0.000 0.007 0.000 {built-in method posix.access}\n",
" 23288 0.007 0.000 0.007 0.000 {method 'sub' of 're.Pattern' objects}\n",
" 12293 0.006 0.000 0.007 0.000 commit.py:614(msg)\n",
" 64047 0.006 0.000 0.006 0.000 {method 'readline' of '_io.BytesIO' objects}\n",
" 45932 0.006 0.000 0.006 0.000 base.py:52(type)\n",
" 34451 0.006 0.000 0.006 0.000 symbolic.py:65(__init__)\n",
" 11528 0.005 0.000 0.006 0.000 parse.py:189(_userinfo)\n",
" 91864 0.006 0.000 0.006 0.000 {built-in method builtins.ord}\n",
" 25344 0.006 0.000 0.006 0.000 util.py:646(__init__)\n",
" 1181 0.006 0.000 0.006 0.000 subprocess.py:1060(__del__)\n",
" 2536 0.003 0.000 0.006 0.000 posixpath.py:150(dirname)\n",
" 11483 0.005 0.000 0.005 0.000 util.py:973(__init__)\n",
" 70416 0.005 0.000 0.005 0.000 {method 'lower' of 'str' objects}\n",
" 45932 0.005 0.000 0.005 0.000 base.py:42(binsha)\n",
" 423 0.001 0.000 0.005 0.000 fun.py:44(is_git_dir)\n",
" 11569 0.004 0.000 0.005 0.000 configparser.py:1363(__iter__)\n",
" 11483 0.005 0.000 0.005 0.000 fun.py:180(to_commit)\n",
" 23292 0.005 0.000 0.005 0.000 pathlib.py:239(splitroot)\n",
" 2294 0.004 0.000 0.005 0.000 threading.py:264(__enter__)\n",
" 1189 0.003 0.000 0.005 0.000 commit.py:529(hash)\n",
" 11528 0.004 0.000 0.005 0.000 parse.py:114(_coerce_args)\n",
" 11483 0.004 0.000 0.005 0.000 base.py:99(__eq__)\n",
" 70485 0.005 0.000 0.005 0.000 {method 'replace' of 'str' objects}\n",
" 1184 0.002 0.000 0.005 0.000 warnings.py:181(_add_filter)\n",
" 11335 0.003 0.000 0.005 0.000 config.py:364(release)\n",
" 756 0.004 0.000 0.004 0.000 ChangeCounter.ipynb:137(update_size)\n",
" 4806 0.003 0.000 0.004 0.000 base.py:123(hexsha)\n",
" 23134 0.004 0.000 0.004 0.000 base.py:290(working_tree_dir)\n",
" 2280 0.003 0.000 0.004 0.000 threading.py:1021(_stop)\n",
" 11569 0.004 0.000 0.004 0.000 config.py:333(_acquire_lock)\n",
" 7168 0.003 0.000 0.004 0.000 conf.py:45(get)\n",
" 2280 0.004 0.000 0.004 0.000 _weakrefset.py:39(_remove)\n",
" 45932 0.004 0.000 0.004 0.000 base.py:60(size)\n",
" 2362 0.003 0.000 0.004 0.000 subprocess.py:1173(poll)\n",
" 1184 0.003 0.000 0.004 0.000 _collections_abc.py:828(keys)\n",
" 1239 0.003 0.000 0.004 0.000 commit.py:623(parents)\n",
" 3466 0.004 0.000 0.004 0.000 {method 'add' of 'set' objects}\n",
" 46017 0.004 0.000 0.004 0.000 configparser.py:363(before_get)\n",
" 1269 0.001 0.000 0.003 0.000 abc.py:117(__instancecheck__)\n",
" 1 0.000 0.000 0.003 0.003 contextlib.py:130(__enter__)\n",
" 23050 0.003 0.000 0.003 0.000 util.py:194(to_native_path_linux)\n",
" 57845 0.003 0.000 0.003 0.000 {built-in method builtins.callable}\n",
" 2282 0.002 0.000 0.003 0.000 threading.py:279(_is_owned)\n",
" 2412 0.001 0.000 0.003 0.000 contextlib.py:448(_exit_wrapper)\n",
" 851 0.002 0.000 0.003 0.000 posixpath.py:337(normpath)\n",
" 756 0.003 0.000 0.003 0.000 ChangeCounter.ipynb:145(update_changes)\n",
" 11569 0.003 0.000 0.003 0.000 configparser.py:1191(converters)\n",
" 255 0.001 0.000 0.003 0.000 util.py:400(expand_path)\n",
" 1 0.000 0.000 0.003 0.003 git.py:39(__init__)\n",
" 30784 0.003 0.000 0.003 0.000 {method 'endswith' of 'bytes' objects}\n",
" 2278 0.003 0.000 0.003 0.000 threading.py:1162(is_alive)\n",
" 1 0.000 0.000 0.003 0.003 git.py:86(_open_repository)\n",
" 1192 0.003 0.000 0.003 0.000 {built-in method posix.stat}\n",
" 1269 0.003 0.000 0.003 0.000 {built-in method _abc._abc_instancecheck}\n",
" 53928 0.003 0.000 0.003 0.000 util.py:160(dst)\n",
" 1184 0.003 0.000 0.003 0.000 {built-in method sys.exc_info}\n",
" 13482 0.003 0.000 0.003 0.000 developer.py:27(__init__)\n",
" 41635 0.003 0.000 0.003 0.000 util.py:154(utcoffset)\n",
" 12661 0.003 0.000 0.003 0.000 {method 'join' of 'str' objects}\n",
" 6838 0.003 0.000 0.003 0.000 threading.py:546(is_set)\n",
" 848 0.001 0.000 0.002 0.000 genericpath.py:39(isdir)\n",
" 102 0.000 0.000 0.002 0.000 parse.py:88(clear_cache)\n",
" 204 0.002 0.000 0.002 0.000 {method 'clear' of 'dict' objects}\n",
" 23052 0.002 0.000 0.002 0.000 {method 'keys' of 'collections.OrderedDict' objects}\n",
" 1190 0.001 0.000 0.002 0.000 __init__.py:1467(info)\n",
" 2278 0.001 0.000 0.002 0.000 base.py:115(__str__)\n",
" 1188 0.002 0.000 0.002 0.000 {method 'remove' of 'list' objects}\n",
" 2374 0.002 0.000 0.002 0.000 __init__.py:1724(isEnabledFor)\n",
" 12672 0.002 0.000 0.002 0.000 {method 'read' of '_io.BytesIO' objects}\n",
" 85 0.000 0.000 0.002 0.000 configparser.py:827(getboolean)\n",
" 2279 0.001 0.000 0.001 0.000 encoding.py:1(force_bytes)\n",
" 13918 0.001 0.000 0.001 0.000 {method 'strip' of 'bytes' objects}\n",
" 10755 0.001 0.000 0.001 0.000 diff.py:411(rename_from)\n",
" 1181 0.001 0.000 0.001 0.000 subprocess.py:1846(_handle_exitstatus)\n",
" 23293 0.001 0.000 0.001 0.000 {method 'reverse' of 'list' objects}\n",
" 257 0.000 0.000 0.001 0.000 posixpath.py:376(abspath)\n",
" 11338 0.001 0.000 0.001 0.000 config.py:707(read_only)\n",
" 3543 0.001 0.000 0.001 0.000 subprocess.py:1858(_internal_poll)\n",
" 12293 0.001 0.000 0.001 0.000 {method 'end' of 're.Match' objects}\n",
" 11567 0.001 0.000 0.001 0.000 base.py:309(bare)\n",
" 85 0.000 0.000 0.001 0.000 configparser.py:806(_get_conv)\n",
" 2282 0.001 0.000 0.001 0.000 threading.py:276(_acquire_restore)\n",
" 2294 0.001 0.000 0.001 0.000 threading.py:267(__exit__)\n",
" 10755 0.001 0.000 0.001 0.000 diff.py:415(rename_to)\n",
" 1184 0.001 0.000 0.001 0.000 cmd.py:1148()\n",
" 1230 0.000 0.000 0.001 0.000 cmd.py:180(dashify)\n",
" 1185 0.001 0.000 0.001 0.000 {built-in method builtins.sorted}\n",
" 3 0.000 0.000 0.001 0.000 config.py:659(write)\n",
" 1184 0.001 0.000 0.001 0.000 warnings.py:477(__exit__)\n",
" 85 0.000 0.000 0.001 0.000 configparser.py:803(_get)\n",
" 85 0.000 0.000 0.001 0.000 cmd.py:612(__init__)\n",
" 11993 0.001 0.000 0.001 0.000 {method 'pop' of 'list' objects}\n",
" 2/1 0.000 0.000 0.001 0.001 config.py:117(flush_changes)\n",
" 2282 0.001 0.000 0.001 0.000 threading.py:273(_release_save)\n",
" 1189 0.001 0.000 0.001 0.000 commit.py:538(author)\n",
" 2412 0.001 0.000 0.001 0.000 {method 'pop' of 'collections.deque' objects}\n",
" 1184 0.001 0.000 0.001 0.000 __init__.py:1455(debug)\n",
" 2279 0.001 0.000 0.001 0.000 cmd.py:632(__getattr__)\n",
" 11569 0.001 0.000 0.001 0.000 {built-in method builtins.iter}\n",
" 2040 0.001 0.000 0.001 0.000 :1()\n",
" 1184 0.001 0.000 0.001 0.000 cmd.py:1058(transform_kwargs)\n",
" 1139 0.001 0.000 0.001 0.000 base.py:90(_set_cache_)\n",
" 11154 0.001 0.000 0.001 0.000 {method 'start' of 're.Match' objects}\n",
" 1 0.000 0.000 0.001 0.001 config.py:791(set_value)\n",
" 2362 0.001 0.000 0.001 0.000 {method 'close' of '_io.BufferedReader' objects}\n",
" 11528 0.001 0.000 0.001 0.000 parse.py:103(_noop)\n",
" 85 0.000 0.000 0.001 0.000 db.py:37(__init__)\n",
" 1184 0.001 0.000 0.001 0.000 cmd.py:1156()\n",
" 2040 0.001 0.000 0.001 0.000 {method 'find' of 'str' objects}\n",
" 1184 0.001 0.000 0.001 0.000 {method 'rfind' of 'bytes' objects}\n",
" 1 0.000 0.000 0.001 0.001 base.py:511(config_writer)\n",
" 4560 0.001 0.000 0.001 0.000 {built-in method _thread.get_ident}\n",
" 257 0.000 0.000 0.001 0.000 genericpath.py:27(isfile)\n",
" 1352 0.001 0.000 0.001 0.000 {method 'rfind' of 'str' objects}\n",
" 1184 0.001 0.000 0.001 0.000 subprocess.py:246(_cleanup)\n",
" 4 0.000 0.000 0.001 0.000 util.py:878(_obtain_lock)\n",
" 4 0.000 0.000 0.001 0.000 util.py:856(_obtain_lock_or_raise)\n",
" 1 0.001 0.001 0.001 0.001 {built-in method posix.open}\n",
" 41 0.000 0.000 0.001 0.000 subprocess.py:2093(terminate)\n",
" 4644 0.001 0.000 0.001 0.000 {method 'release' of '_thread.lock' objects}\n",
" 85 0.000 0.000 0.001 0.000 genericpath.py:16(exists)\n",
" 85 0.000 0.000 0.001 0.000 loose.py:77(__init__)\n",
" 41 0.001 0.000 0.001 0.000 {method 'close' of '_io.BufferedWriter' objects}\n",
" 2280 0.000 0.000 0.000 0.000 {method 'discard' of 'set' objects}\n",
" 2286 0.000 0.000 0.000 0.000 {method '__enter__' of '_thread.lock' objects}\n",
" 41 0.000 0.000 0.000 0.000 subprocess.py:2061(send_signal)\n",
" 1184 0.000 0.000 0.000 0.000 contextlib.py:530(__enter__)\n",
" 86 0.000 0.000 0.000 0.000 base.py:464(_get_config_path)\n",
" 4737 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
" 1184 0.000 0.000 0.000 0.000 _collections_abc.py:854(__init__)\n",
" 1189 0.000 0.000 0.000 0.000 git.py:134(get_commit_from_gitpython)\n",
" 1184 0.000 0.000 0.000 0.000 cmd.py:1149()\n",
" 4601 0.000 0.000 0.000 0.000 {method 'insert' of 'list' objects}\n",
" 2288 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.RLock' objects}\n",
" 1 0.000 0.000 0.000 0.000 repository.py:240()\n",
" 3479 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.lock' objects}\n",
" 4 0.000 0.000 0.000 0.000 thread.py:161(submit)\n",
" 85 0.000 0.000 0.000 0.000 re.py:197(search)\n",
" 2 0.000 0.000 0.000 0.000 pathlib.py:1062(resolve)\n",
" 85 0.000 0.000 0.000 0.000 _collections_abc.py:820(__contains__)\n",
" 41 0.000 0.000 0.000 0.000 {built-in method posix.kill}\n",
" 427 0.000 0.000 0.000 0.000 posixpath.py:60(isabs)\n",
" 4 0.000 0.000 0.000 0.000 thread.py:180(_adjust_thread_count)\n",
" 3552 0.000 0.000 0.000 0.000 {built-in method _warnings._filters_mutated}\n",
" 2040 0.000 0.000 0.000 0.000 parse.py:419(_checknetloc)\n",
" 2 0.000 0.000 0.000 0.000 posixpath.py:391(realpath)\n",
" 85 0.000 0.000 0.000 0.000 re.py:288(_compile)\n",
" 3 0.000 0.000 0.000 0.000 config.py:615(_write)\n",
" 2 0.000 0.000 0.000 0.000 posixpath.py:400(_joinrealpath)\n",
" 85 0.000 0.000 0.000 0.000 base.py:113(__init__)\n",
" 45 0.000 0.000 0.000 0.000 config.py:618(write_section)\n",
" 84 0.000 0.000 0.000 0.000 base.py:197(abspath)\n",
" 80 0.000 0.000 0.000 0.000 mman.py:408(collect)\n",
" 1228 0.000 0.000 0.000 0.000 {method 'update' of 'dict' objects}\n",
" 1181 0.000 0.000 0.000 0.000 {built-in method posix.WIFSTOPPED}\n",
" 8 0.000 0.000 0.000 0.000 {built-in method posix.lstat}\n",
" 1189 0.000 0.000 0.000 0.000 commit.py:503(__init__)\n",
" 1184 0.000 0.000 0.000 0.000 {built-in method sys.audit}\n",
" 255 0.000 0.000 0.000 0.000 posixpath.py:228(expanduser)\n",
" 1181 0.000 0.000 0.000 0.000 {built-in method posix.waitstatus_to_exitcode}\n",
" 253 0.000 0.000 0.000 0.000 cmd.py:368(is_cygwin)\n",
" 80 0.000 0.000 0.000 0.000 mman.py:303(_collect_lru_region)\n",
" 1139 0.000 0.000 0.000 0.000 diff.py:86(_process_diff_args)\n",
" 1184 0.000 0.000 0.000 0.000 {method 'pop' of 'dict' objects}\n",
" 48 0.000 0.000 0.000 0.000 cmd.py:1042(transform_kwarg)\n",
" 5 0.000 0.000 0.000 0.000 _base.py:201(as_completed)\n",
" 1139 0.000 0.000 0.000 0.000 util.py:257(_set_cache_)\n",
" 255 0.000 0.000 0.000 0.000 posixpath.py:284(expandvars)\n",
" 2285 0.000 0.000 0.000 0.000 {method 'locked' of '_thread.lock' objects}\n",
" 84 0.000 0.000 0.000 0.000 base.py:266(__ne__)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:636(__exit__)\n",
" 1 0.000 0.000 0.000 0.000 thread.py:216(shutdown)\n",
" 1 0.000 0.000 0.000 0.000 git.py:92(_discover_main_branch)\n",
" 1 0.000 0.000 0.000 0.000 base.py:792(active_branch)\n",
" 85 0.000 0.000 0.000 0.000 configparser.py:1163(_convert_to_boolean)\n",
" 756 0.000 0.000 0.000 0.000 ChangeCounter.ipynb:155(update_elems)\n",
" 1 0.000 0.000 0.000 0.000 symbolic.py:288(_get_reference)\n",
" 45 0.000 0.000 0.000 0.000 config.py:216(items_all)\n",
" 6 0.000 0.000 0.000 0.000 _base.py:179(_yield_finished_futures)\n",
" 763 0.000 0.000 0.000 0.000 {built-in method _stat.S_ISDIR}\n",
" 45 0.000 0.000 0.000 0.000 config.py:218()\n",
" 2 0.000 0.000 0.000 0.000 util.py:883(_release_lock)\n",
" 1 0.000 0.000 0.000 0.000 thread.py:123(__init__)\n",
" 2 0.000 0.000 0.000 0.000 pathlib.py:1090(stat)\n",
" 1 0.000 0.000 0.000 0.000 util.py:139(rmfile)\n",
" 88 0.000 0.000 0.000 0.000 config.py:786(_value_to_string)\n",
" 2 0.000 0.000 0.000 0.000 weakref.py:370(remove)\n",
" 1 0.000 0.000 0.000 0.000 {built-in method posix.remove}\n",
" 84 0.000 0.000 0.000 0.000 base.py:261(__eq__)\n",
" 4 0.000 0.000 0.000 0.000 threading.py:421(acquire)\n",
" 253 0.000 0.000 0.000 0.000 util.py:347(is_cygwin_git)\n",
" 1 0.000 0.000 0.000 0.000 repository.py:44(__init__)\n",
" 132 0.000 0.000 0.000 0.000 config.py:209(getall)\n",
" 1 0.000 0.000 0.000 0.000 symbolic.py:685(from_path)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:77(sanity_check_filters)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:24(__init__)\n",
" 85 0.000 0.000 0.000 0.000 base.py:70(__init__)\n",
" 1 0.000 0.000 0.000 0.000 repository.py:256(_split_in_chunks)\n",
" 3 0.000 0.000 0.000 0.000 config.py:212(items)\n",
" 3 0.000 0.000 0.000 0.000 config.py:214()\n",
" 171 0.000 0.000 0.000 0.000 {built-in method _stat.S_ISREG}\n",
" 4 0.000 0.000 0.000 0.000 _base.py:318(__init__)\n",
" 4 0.000 0.000 0.000 0.000 _base.py:418(result)\n",
" 88 0.000 0.000 0.000 0.000 encoding.py:11(force_text)\n",
" 1 0.000 0.000 0.000 0.000 threading.py:415(__init__)\n",
" 57 0.000 0.000 0.000 0.000 {method 'find' of 'bytes' objects}\n",
" 1 0.000 0.000 0.000 0.000 conf.py:191(build_args)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:157(_create_and_install_waiters)\n",
" 4 0.000 0.000 0.000 0.000 pathlib.py:629(__fspath__)\n",
" 57 0.000 0.000 0.000 0.000 {method 'rstrip' of 'bytes' objects}\n",
" 1 0.000 0.000 0.000 0.000 conf.py:287(_check_timezones)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:79(__init__)\n",
" 2 0.000 0.000 0.000 0.000 threading.py:793(_maintain_shutdown_locks)\n",
" 80 0.000 0.000 0.000 0.000 {method 'values' of 'dict' objects}\n",
" 4 0.000 0.000 0.000 0.000 thread.py:47(__init__)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:293(_replace_timezone)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:54(_sanity_check_repos)\n",
" 1 0.000 0.000 0.000 0.000 {built-in method math.ceil}\n",
" 5 0.000 0.000 0.000 0.000 {method 'put' of '_queue.SimpleQueue' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'replace' of 'datetime.datetime' objects}\n",
" 85 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}\n",
" 1 0.000 0.000 0.000 0.000 _base.py:146(__init__)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:63(__init__)\n",
" 2 0.000 0.000 0.000 0.000 repository.py:148(_is_remote)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:65(_check_only_one_from_commit)\n",
" 4 0.000 0.000 0.000 0.000 threading.py:90(RLock)\n",
" 1 0.000 0.000 0.000 0.000 configparser.py:892(set)\n",
" 1 0.000 0.000 0.000 0.000 reference.py:46(__init__)\n",
" 7 0.000 0.000 0.000 0.000 conf.py:36(set_value)\n",
" 8 0.000 0.000 0.000 0.000 util.py:851(_has_lock)\n",
" 1 0.000 0.000 0.000 0.000 git.py:322(__del__)\n",
" 1 0.000 0.000 0.000 0.000 contextlib.py:279(helper)\n",
" 2 0.000 0.000 0.000 0.000 weakref.py:428(__setitem__)\n",
" 2 0.000 0.000 0.000 0.000 threading.py:803()\n",
" 1 0.000 0.000 0.000 0.000 conf.py:71(_check_only_one_to_commit)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:149(__enter__)\n",
" 2 0.000 0.000 0.000 0.000 conf.py:181(only_one_filter)\n",
" 8 0.000 0.000 0.000 0.000 {method 'partition' of 'str' objects}\n",
" 1 0.000 0.000 0.000 0.000 util.py:844(__del__)\n",
" 1 0.000 0.000 0.000 0.000 contextlib.py:102(__init__)\n",
" 1 0.000 0.000 0.000 0.000 reference.py:100(name)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:153(__exit__)\n",
" 1 0.000 0.000 0.000 0.000 threading.py:572(clear)\n",
" 2 0.000 0.000 0.000 0.000 util.py:847(_lock_file_path)\n",
" 3 0.000 0.000 0.000 0.000 config.py:699(_assure_writable)\n",
" 4 0.000 0.000 0.000 0.000 _base.py:225()\n",
" 8 0.000 0.000 0.000 0.000 {method '__enter__' of '_thread.RLock' objects}\n",
" 2 0.000 0.000 0.000 0.000 {method 'difference_update' of 'set' objects}\n",
" 1 0.000 0.000 0.000 0.000 conf.py:142(get_starting_commit)\n",
" 4 0.000 0.000 0.000 0.000 _base.py:388(__get_result)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:114(_check_correct_filters_order)\n",
" 3 0.000 0.000 0.000 0.000 git.py:63(repo)\n",
" 8 0.000 0.000 0.000 0.000 {built-in method _stat.S_ISLNK}\n",
" 1 0.000 0.000 0.000 0.000 pathlib.py:708(name)\n",
" 5 0.000 0.000 0.000 0.000 {method 'remove' of 'set' objects}\n",
" 4 0.000 0.000 0.000 0.000 {method 'lstrip' of 'str' objects}\n",
" 2 0.000 0.000 0.000 0.000 pathlib.py:1430(expanduser)\n",
" 1 0.000 0.000 0.000 0.000 conf.py:165(get_ending_commit)\n",
" 4 0.000 0.000 0.000 0.000 {built-in method time.monotonic}\n",
" 1 0.000 0.000 0.000 0.000 util.py:840(__init__)\n",
" 2 0.000 0.000 0.000 0.000 conf.py:189()\n",
" 2 0.000 0.000 0.000 0.000 {method 'remove' of 'collections.deque' objects}\n",
" 4 0.000 0.000 0.000 0.000 {method 'acquire' of '_thread.RLock' objects}\n",
" 1 0.000 0.000 0.000 0.000 configparser.py:663(has_section)\n",
" 4 0.000 0.000 0.000 0.000 {method 'release' of '_thread.RLock' objects}\n",
" 1 0.000 0.000 0.000 0.000 __init__.py:230(utcoffset)\n",
" 1 0.000 0.000 0.000 0.000 _base.py:633(__enter__)\n",
" 1 0.000 0.000 0.000 0.000 configparser.py:366(before_set)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"cProfile.run('debuggingbook_change_counter(ChangeCounter)', sort='cumulative')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Yes, that's an awful lot of functions, but we can quickly narrow things down. The `cumtime` column is sorted by largest values first. We see that the `debuggingbook_change_counter()` method at the top takes up all the time – but this is not surprising, since it is the method we called in the first place. This calls a method `mine()` in the `ChangeCounter` class, which does all the work."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"The next places are more interesting: almost all time is spent in a single method, named `modifications()`. This method determines the difference between two versions, which is an expensive operation; this is also supported by the observation that half of the time is spent in a `diff()` method."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"This profile thus already gets us a hint on how to improve performance: Rather than computing the diff between versions for _every_ version, we could do so _on demand_ (and possibly cache results so we don't have to compute them twice). Alas, this (slow) functionality is part of the \n",
"underlying [PyDriller](https://pydriller.readthedocs.io/) Python package, so we cannot fix this within the `ChangeCounter` class. But we could file a bug with the developers, suggesting a patch to improve performance."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Sampling Execution Profiles\n",
"\n",
"Instrumenting code is _precise_, but it is also _slow_. An alternate way to measure performance is to _sample_ in regular intervals which functions are currently active – for instance, by examining the current function call stack. The more frequently a function is sampled as active, the more time is spent in that function."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"One profiler for Python that implements such sampling is [Scalene](https://github.com/plasma-umass/scalene) – a high-performance, high-precision CPU, GPU, and memory profiler for Python. We can invoke it on our example as follows:\n",
"\n",
"```sh\n",
"$ scalene --html test.py > scalene-out.html\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"where `test.py` is a script that again invokes\n",
"\n",
"```python\n",
"debuggingbook_change_counter(ChangeCounter)\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"The output of `scalene` is sent to a HTML file (here, `scalene-out.html`) which is organized by _lines_ – that is, for each line, we see how much it contributed to overall execution time. Opening the output `scalene-out.html` in a HTML browser, we see these lines:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"![](PICS/scalene-out.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"As with `cProfile`, above, we identify the `mine()` method in the `ChangeCounter` class as the main performance hog – and in the `mine()` method, it is the iteration over all modifications that takes all the time. Adding the option `--profile-all` to `scalene` would extend the profile to all executed code, including the `pydriller` third-party library."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Besides relying on sampling rather that tracing (which is more efficient) and breaking down execution time by line, `scalene` also provides additional information on memory usage and more. If `cProfile` is not sufficient, then `scalene` will bring profiling to the next level."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Improving Performance"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Identifying a culprit is not always that easy. Notably, when the first set of obvious performance hogs is fixed, it becomes more and more difficult to squeeze out additional performance – and, as stated above, such optimization may be in conflict with readability and maintainability of your code. Here are some simple ways to improve performance:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* **Efficient algorithms**. For many tasks, the simplest algorithm is not always the best performing one. Consider alternatives that may be more efficient, and _measure_ whether they pay off.\n",
"\n",
"* **Efficient data types**. Remember that certain operations, such as looking up whether an element is contained, may take different amounts of time depending on the data structure. In Python, a query like `x in xs` takes (mostly) constant time if `xs` is a set, but linear time if `xs` is a list; these differences become significant as the size of `xs` grows.\n",
"\n",
"* **Efficient modules**. In Python, most frequently used modules (or at least parts of) are implemented in C, which is way more efficient than plain Python. Rely on existing modules whenever possible. Or implement your own, _after_ having measured that this may pay off."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"These are all things you can already use during programming – and also set up your code such that exchanging, say, one data type by another will still be possible later. This is best achieved by hiding implementation details (such as the used data types) behind an abstract interface used by your clients."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"But beyond these points, remember the famous words by [Donald E. Knuth](https://en.wikipedia.org/wiki/Donald_Knuth):"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:38:37.915524Z",
"iopub.status.busy": "2024-01-17T21:38:37.915336Z",
"iopub.status.idle": "2024-01-17T21:38:37.917428Z",
"shell.execute_reply": "2024-01-17T21:38:37.917105Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"from bookutils import quiz"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-17T21:38:37.919437Z",
"iopub.status.busy": "2024-01-17T21:38:37.919287Z",
"iopub.status.idle": "2024-01-17T21:38:37.925472Z",
"shell.execute_reply": "2024-01-17T21:38:37.925160Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" \n",
"
\n",
"
Quiz
\n",
"
\n",
"
Donald E. Knuth said: \"Premature optimization...\"