Performance: Using coz to point out hot spots

I just ran into this interesting benchmarking program:

I ran it on swipl (I think I did this a couple of times to get an 80MB profile.coz file, took about two hours, maybe more):

$ cd /tmp/swipl-devel/bench
$ for i in $(seq 330); do coz run -b /tmp/swipl-devel/build.release/%  --- swipl run.pl; done

I placed a throughput benchmark in function PL_next_solution(...) in pl-wam.c (you need to #include “coz.h”):

int
PL_next_solution(qid_t qid)
{ GET_LD
  register_file REGISTERS = {.qid = qid};	/* Active registers */
  Code PC;					/* program counter */
  exception_frame THROW_ENV;			/* PL_thow() environment */

	COZ_PROGRESS;   // <---- Here, this is a counter


#if O_VMI_FUNCTIONS
  register_file *registers = &REGISTERS;

#else /* O_VMI_FUNCTIONS */
...

I got some interesting results after running for perhaps a couple of hours:

I chose “impact” as the sorting mode for the graphs, which come from uploading the profile.coz file to this website: coz plot

  • The first graph says that if line 197 in pl-index.c is sped up by 23% then PL_next_solution(..) will be reached 90% more times per second!
  • The second graph says that if line 2497 in pl-vmi.c is sped up by 55% then PL_next_solution(..) will be reached 55% more times per second!
  • The eighth graph, biggest bang for the buck, says that if line 1939 in pl-vmi.c is sped up by 10% then PL_next_solution(..) will be reached 56% more times per second!

And so on.
If you sort graphics by Min. speedup you get this:

  • The fifth graph says that if you speed up line 509 of pl-inline.h by 50% you will slow down the throughput of PL_next_solution(...) by 26%.

Now that is quite a great benchmarking software. They were able to speedup SQLite by 25% with this tool. You can see more about its operating methods here (I think this is one of the authors):

I figured this may help @dmchurch in his optimization efforts.

I placed the COZ_PROGRESS counter in PL_next_solution(..) because that is where we get the answer after calling a predicate.

3 Likes

Oh wow, this is REALLY cool! I’m definitely going to be checking this out. (Also, it took me around three or four rereads to realize this said “causal” profiling and not “casual”… :sweat_smile:)

Oh, and fyi, it’s “their” (or “her”, if necessary). Anyway, thanks so much for the tip! I can’t wait to get the refactors I’m doing out of the way so I can start playing around with this :grinning_face_with_smiling_eyes:

2 Likes