Reproduction Steps
- Run this script:
local HttpService = game:GetService("HttpService")
local tab = {
["$5"] = {
["1"] = 15,
["2"] = -0.098,
["3"] = -330
}
}
print('Table: ', tab)
print('JSON: ', HttpService:JSONEncode(tab))
It will print:
Table: ▼ {
["$5"] = ▼ {
["1"] = 15,
["2"] = -0.098,
["3"] = -330
}
}
JSON: {"$5":{"2":-0.0980000000000000037747582837255,"3":-330,"1":15}}
Expected Behavior
The JSON float number should NOT be converted to 33 bytes.
Actual Behavior
This is a very serious problem, since the DataStore stores data in JSON format, and in this case, float numbers will have an absurd increase in size.
For example:
A table of 1 million positive floats using only ONE DECIMAL PLACE (1.3, 0.5, 3.7, etc) originally takes up 3 bytes per number. In this way, occupation 3 million bytes.
But, as we see, due to this bug, the same table will occupy 33 bytes per number (11 times more!), generating a final size of 31 MB, making it impossible to use it in DataStore, as this is limited to 4 MB.
Workaround
In this case, I am forced to transform the float number into a string, which will take up two additional bytes for the quotes.
While it’s possible to work around this bug, it is important to investigate, as it is likely that many developers can inappropriately bump into a DataStore limit.
Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly