C#_Baking time difference: docking panel vs Custom GH Component

Hi,
I have c# code block (method) which is used in Grasshopper custom component and also in Rhino custom docking panel developed. Basically code adds x number of InstanceDefinitions and bakes y number of InstanceObjects. When custom gh component is used for baking, nearly 10K blocks are baked whitin a second. However when same code gets triggered from docking panel it takes almost a half a minute to bake same number of blocks.

Why this is happening? How can I have same performance from docking panel as well.

Thanks in Advance!

Without the code is difficult to guess, but a common mistake is having some code that updates the UI or viewports every time an object is added to the document, and then calling this on a loop for many objects. Make sure to update UI and viewports only once, after all objects are added.