So wouldn’t it just be faster to use attributes with the same functionality?
Actually, yes. Depends on your use case.
FastValue supports tables but how much faster is it when setting up Attributes with json?
Also could you provide the code you used for benchmarking?
Very slow, you could use FastValue in that case.
Alternative Approaches:
ModuleScripts
ModuleScripts provide globally accessible tables within the entire datamodel, you can write your own code to replicate these states into the client or using FastValue.
Values Objects (yes again!)
If you are using simple values (numbers, strings, booleans) you can attempt to distribute these values into ValueBases stored in a folder. This method allows you to directly store key-value pairs in the Roblox hierarchy.
You can still go with the JSON method tho, which will be slower and more complex to debug. : /
Sure, wrote this in a hurry so the code runs with hopes & prayers (and a little duct tape)
local function calculateMedian(arr)
local n = #arr
table.sort(arr)
if n % 2 == 1 then
return arr[math.ceil(n / 2)]
else
local mid1 = arr[n / 2]
local mid2 = arr[n / 2 + 1]
return (mid1 + mid2) / 2
end
end
local function convert_seconds(seconds)
local milliseconds = seconds * 1000
local microseconds = milliseconds * 1000
if milliseconds < 1 then
return ("%.2f"):format(microseconds), "microseconds"
elseif milliseconds < 1000 then
return ("%.2f"):format(milliseconds), "milliseconds"
else
return ("%.2f"):format(seconds), "seconds"
end
end
local FastValue = require(workspace.FastValue)
local FastValue_Get = FastValue.Get
local FastValue_Set = FastValue.Set
local StringValue = workspace.StringValue
local FASTVALUE_Results = {}
local STRINGVALUE_Results = {}
local Value = game:GetService("HttpService"):GenerateGUID(false)
for FastValue_i = 1, 2 ^ 16 do
local t = os.clock()
FastValue_Set("Key", Value)
FASTVALUE_Results[#FASTVALUE_Results + 1] = os.clock() - t
end
for StringValue_i = 1, 2 ^ 16 do
local t = os.clock()
StringValue.Value = Value
STRINGVALUE_Results[#STRINGVALUE_Results + 1] = os.clock() - t
end
print("The 50th percentile (median) of StringValue (SETTING NEW .Value): ", convert_seconds(calculateMedian(STRINGVALUE_Results)))
print("The 50th percentile (median) of FastValue (USING THE SET FN): ", convert_seconds(calculateMedian(FASTVALUE_Results)))
- Add a StringValue object in the workspace named “StringValue”
- Add the FastValue module in the workspace