You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm heavily invested in making custom plugins for lwc but it's been nagging me what the best most performant way of writing them is. There seems to be many discrepancies in the plugin-examples folder and I'm struggling to see what the whole point/benefit of having an entirely separate renderer class is when it seems like any trivial action like scrolling or scaling the chart will call the plugin updateAllViews() which in turn calls each paneView's update() right before renderer().draw() is called.
It seems like all the calculations like timeToCoordinate() that are needed for the renderer are supposed to be calculated and cached in the paneView and passed to the renderer, but most of the time all these calculations are changed for every render anyways, so where's the benefit? Every single render()#draw() seems to be proceeded by update() regardless.
Even worse, many of the plugin examples seem to return a whole new class instance in renderer() (example)
And this gets called constantly, even as the mouse is moving around. At the very least I would have expected the renderer to be cached and reused instead of constantly getting recreated, no? In some of my plugins I instead create the renderer once in the paneView constructor and return the cached version. Seems to work fine, and that is certainly going to be more easy on the garbage collector than making thousands of new classes on every tick. So what am I missing here? What was the thinking behind this plugin architecture and what are the best practices?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm heavily invested in making custom plugins for lwc but it's been nagging me what the best most performant way of writing them is. There seems to be many discrepancies in the plugin-examples folder and I'm struggling to see what the whole point/benefit of having an entirely separate renderer class is when it seems like any trivial action like scrolling or scaling the chart will call the plugin
updateAllViews()
which in turn calls each paneView'supdate()
right beforerenderer().draw()
is called.It seems like all the calculations like
timeToCoordinate()
that are needed for the renderer are supposed to be calculated and cached in the paneView and passed to the renderer, but most of the time all these calculations are changed for every render anyways, so where's the benefit? Every singlerender()#draw()
seems to be proceeded byupdate()
regardless.Even worse, many of the plugin examples seem to return a whole new class instance in
renderer()
(example)And this gets called constantly, even as the mouse is moving around. At the very least I would have expected the renderer to be cached and reused instead of constantly getting recreated, no? In some of my plugins I instead create the renderer once in the paneView constructor and return the cached version. Seems to work fine, and that is certainly going to be more easy on the garbage collector than making thousands of new classes on every tick. So what am I missing here? What was the thinking behind this plugin architecture and what are the best practices?
Beta Was this translation helpful? Give feedback.
All reactions