<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Profiling on Shai Asher</title><link>https://slow-is-smooth.io/tags/profiling/</link><description>Recent content in Profiling on Shai Asher</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 12 Mar 2023 09:00:00 +0200</lastBuildDate><atom:link href="https://slow-is-smooth.io/tags/profiling/index.xml" rel="self" type="application/rss+xml"/><item><title>Every Function Is a Hook</title><link>https://slow-is-smooth.io/blog/every-function-is-a-hook/</link><pubDate>Sun, 12 Mar 2023 09:00:00 +0200</pubDate><guid>https://slow-is-smooth.io/blog/every-function-is-a-hook/</guid><description>&lt;p&gt;Attaching the same two-line BPF program to the &lt;code&gt;getpid()&lt;/code&gt; system call made each call 7.4&#10;nanoseconds slower when it went in through fentry, 27 through a kprobe, 89&#10;through a kretprobe, and 310 when the kprobe had to fall back to a breakpoint instruction.&#10;A uprobe on a two-instruction function in an ordinary program made each call of it&#10;8.1 microseconds slower, about 27,000 times what the function costs on its&#10;own. The program did the same thing every time: it added one to a counter. What changed was the road&#10;the kernel took to reach it.&lt;/p&gt;</description></item><item><title>Profiling Below the Bytecode</title><link>https://slow-is-smooth.io/blog/profiling-below-the-bytecode/</link><pubDate>Sun, 16 Feb 2020 09:00:00 +0200</pubDate><guid>https://slow-is-smooth.io/blog/profiling-below-the-bytecode/</guid><description>&lt;p&gt;A Python 3.8 program that splits strings, adds up their lengths and writes JSON takes 4.5 seconds.&#10;&lt;code&gt;cProfile&lt;/code&gt; says 3.1 of them are in &lt;code&gt;str.split&lt;/code&gt;. &lt;code&gt;py-spy&lt;/code&gt; says two thirds of the samples are in the list&#10;comprehension that calls it. &lt;code&gt;perf&lt;/code&gt;, the Linux profiler, says a third of the time is in a C function&#10;called &lt;code&gt;collect&lt;/code&gt;, and another quarter in functions it calls, and it doesn&amp;rsquo;t name a single Python&#10;function. All three are right about what they measure, and only one of them found the real problem:&#10;the cycle collector from Part 4, walking three million lists that will never be garbage. With the&#10;collector turned off, the same program runs in 1.9 seconds.&lt;/p&gt;</description></item></channel></rss>