Prepare a set of parameters for reuse in multiple panels I need to calculate a set of parameters for each draw cycle, which are needed in multiple draw() functions from different panels. Currently i calculate the parameters within each panel's draw() function which appears to be very inefficient. 

So i search for a way to add a function which runs once per draw cycle. Then all panels can safely use the pre calculated parameters as needed.

Simple Example:

I need this set in 2 panels:

bones = set([b.name for b in bpy.context.selected_pose_bones])


How can i calculate this set once and then reuse the set in both panels ?
Answer is rather simple, afaik: you cannot.

There may be some ways to cache that result, maybe in scene object, but we do not have any set-like type of property in RNA anyway, and you would have to handle update of it, which would not be trivial.

Note however that I doubt this to be a real performance bottleneck, unless you have tens of thousands of bones…

And you should use context given to panel's draw func, and do not need to use list comprehension to create a set, there is a set comprehension too:

bones = {b.name for b in context.selected_pose_bones}