Is it okay to use ObjectValues/Attributes instead of Tables for Data Store?

So, I’ve finished my new Framework Data Service but I’m not satisfied with it… Clients have to use RemoteFunctions to retrieve their cache, and I’m not sure how much does it affect my game performance.

As I said, I tried to use RemoteFunctions and it’s “perfect”? Thank everyone.

I would avoid using remote functions, period. If you want to transfer data across the client/server boundary, use remote events.

1 Like

What makes you say this?

I myself would have the client invoke a remote function on the server requesting the cached data, then the server can return back with the data.

In regards to the use of instances, I guess this could work but I assume there will probably be more management and memory consumption overhead compared to just storing data in a table / dictionary.

1 Like

This is probably right, firing a RemoteEvent can avoid doing so many requests in so many Local Scripts.

Or sometimes this can be worse, because there’s games that doesn’t use so much Local Scripts.

Remote functions yield, which creates messy and completely asynchronous behavior.

Let’s say that you invoke the server as a client. You are assuming the following:

  • The information returned is accurate
  • There will be at least one userdata value returned, even if it’s nil
  • That it should not take longer to process than you intended

If the first or second fluke, that would be on you, and yeah you can fix it. However, you have to be careful with the third, because a number of things could happen. What if the call fails, and the client infinitely yields? Or, in a less-bad scenario, what if there is an issue with the server processing time that relies on the client to yield code for a long time?

Using remote events allows the client to request data and continue to operate without issue. Using that same (or a different) remote takes your code from an asynchronous approach to an event-based synchronous approach, which is much healthier for your game.

1 Like

But aren’t remote events also asynchronous and also have the unlikely possibility of failing too.

Remote functions essentially allow for two-way communication.

If you wanted to setup a newly connected client with some cached data, you could have the client invoke the server asking for the initial data, then the server can respond back with the request.

With remote events however if the server fired an event to setup the client, it could fire the event before the client has even loaded the script to handle the event. Which means you’ll likely end up having to spam multiple events until the data is passed successfully (wasting valuable bandwidth).

It’s a little unclear if we are talking about generally updating the client with some newly updated data (which case I’d too agree with using remote events) or performing an initial data setup (which I would therefore use a remote function).

1 Like

No.

The difference is that if it fails, you will not have an infinite hang.

1 Like

Maybe I can solve this by doing a ModuleScript with a function that stores and returns a Server Invoke (if the last one expired) or returns the last Server Invoke (if the last one isn’t expired)?

--ModuleScript
local module = {}
local requestData = game:GetService("ReplicatedStorage").requestData
lastData = nil
Renewing = false

function module:requestData()
    if not lastData and not Renewing then
       Renewing = true
        lastData = requestData:InvokeServer()
        spawn(function()
            wait(1)
            Renewing = false
            lastData = nil
        end)
    end
    return lastData
end

return module

That solution does not work. Even if you put the invocation on another thread, an infinite hang can cause a memory leak.

1 Like

I think that using RemoteFunctions to retrieve data can be an efficient way to get data from the cache. However, it might not be the best way to do it depending on the type of game you’re creating. If your game has a lot of players and a lot of data, RemoteFunctions might not be able to handle the load. In this case, it might be best to use a dedicated backend service that can handle the load more efficiently, such as a database or cloud service.

On the other hand, if your game is small and has fewer players, then RemoteFunctions might be a good option. It can provide a quick and easy way to get data from the cache without having to manage a backend service.

Ultimately, it depends on the type of game you’re creating and the number of players that will be playing it. If you’re unsure, it might be best to test both options to see which works best for your game.

1 Like