Are pcalls heavy on memory/performance?

Are they? And how many pcalls would you say is too much (rough estimate?). And do they impact memory/performance more or less depending on what the function is?

4 Likes

I think that it doesn’t have a impact on performance and memory. Maybe just a little but i wouldn’t worry about it.

3 Likes

While you can use pcalls for this, a much cleaner solution would be to pass properties as arguments to your module similar to how TweenService already does.

To answer your other question, no, pcalls do not automatically retry whatever condition failed. You need to setup your own logic for that.

1 Like

They are but barely. Like REALLY barely. So barely that you can use as many as you want and it won’t really do much performance damage. So short answer is: no.

Also please move this to #help-and-feedback:scripting-support and not #development-discussion! Thanks! ^_^

4 Likes

pcalls are pretty lightweight because they’re simple. VM logic that would normally throw an error instead returns it with the success boolean. There is no automatic retry logic because pcall is a primitive for a single protected call. You’d sooner find a performance issue with creating functions than pcalling them.

There’s an issue with what you’re hoping to accomplish. A Tween’s creation will fail if the Instance doesn’t have all the properties that are being interpolated. Therefore, none of the properties will be interpolated because 1 or more don’t exist. You can still do this with separate pcalls but I do not recommend it.

I just want to add on, this doesnt mean pcalls are the solution for bad code. Most times there are better solutions that are cleaner, and more performant (even if by not much). Pcalls should only be used for datastores, web API calls, and similar.

Heres a post on using pcalls: Pcalls - When and how to use them

Yes I know, I hadn’t created a tweenhandler yet I was just wondering if the tween would still play even if you used a pcall, which I now know it won’t because I’ve tested it myself too. But thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.