# Why PieChart Callout is so slow?

I was testing PieChart using the following random data before touching my own dataset and found the ChartLabels using the Callout function is so slow. I wonder why and is there anyway to improve its performance? I tried PerformanceGoal→"Speed" (learned from here) as the PieChart option, it seems to me not very effective. On my laptop, the following three ChartLabels option yield 0.204785, 15.0763, 48.0431 with AbsoluteTiming.

Generate data

SeedRandom[14];
list = RandomInteger[{1, 100}, 300];
stats = Counts@list
rules=Normal@stats;


Plot PieChart

Table[AbsoluteTiming[PieChart[stats, ChartStyle -> "Pastel", ImageSize -> Full, opts]],
{opts, {
ChartLabels -> Callout[Keys@stats, Automatic], (*slow*)
ChartLabels ->
Callout[Row[{Style[#[[1]], Italic], " = ", Style[#[[2]]]}] & /@
rules, Automatic] (* too slow *)
}}]


BTW, when I changed the Head to BarChart with the rest the same, it is faster. However, the Callout slow issue remained.

—————————————————————————

Further tests on my laptop showed with specific ImageSize, the AbsoluteTiming was sometimes short and sometimes long. For example. 800 or 1000 still took long execution time (> 40 sec) while 1200 and 2000 were faster (< 10 sec).

—————————————————————————

I tried the following. In general, it was faster on my laptop.

callout=List@@@(Normal@stats);
statsCallout=Callout[#[[2]],#[[1]]<>" = "<>ToString@#[[2]]]& /@ callout;
PieChart[statsCallout, ImageSize->1200, ChartStyle->"Pastel"]//AbsoluteTiming

• If you do: callouts = Callout[Row[{Style[#[[1]], Italic], " = ", Style[#[[2]]]}] & /@ rules, Automatic]; and then PieChart[stats, ChartLabels->callouts], I think it should work fine. I imagine it's redoing the Map for every single label. May 14, 2021 at 14:35
• @CarlLange Thanks for editing the code, you lost the ImageSize→Full option in my original post:) But because of this, I found out the reason LoL. With Callout pre-calculated, the improvement of timing seems to me marginally, 47ish comparing to the original 48 with ImageSize->Full. But if I changed ImageSize to a specific size, say 2000 instead of Full, the timing was reduced greatly. I do not know why, but it worked. May 15, 2021 at 1:47
• Oh wow, sorry about that! I'm glad it inadvertently helped though. May 15, 2021 at 8:26