Script optimization question

I have a viewportFrame inventory Gui, that uses RenderStepped to spin the camera around the item in the viewport.
I was wondering:
Is it better to have 1 handler script, that takes care of ALL the items and viewports, or have a new script inside every viewportFrame, that handles that item and its viewport preview?

With 140 items, the script usage is around 6%, which is not great.
I already have optimization measures, such as:

  • RenderStepped loop gets disconnected when inventory is closed
  • The viewports update only if they are visible on the screen

Changing my script to 1 per item wouldnt be an issue, and it would also help with another problem.

Any help?

EDIT: I made a script for each viewport, and the script usage dropped only by 0.25%, but it also fixed a issue with the usage getting bigger with each item you select.

Although I don’t know the specifics, I would assume the TweenService would have slightly better optimization. Instead of using RenderStepped to spin the camera, you could just create a Tween for all the ViewPorts. On top of this, you could also implement some sort of detection to check whether the ViewPort is currently on the screen, if its not, you can pause or stop the Tween.

I dont know if I could do it that way, since my code calculates the item positioning and distance