Extremely slow json.decode(...)

I’m trying to build a small game in Defold for the past couple of weeks and I’ve just bumped into the first stumbling block.

I have a Json file, around 4Mb in size that I read using sys.load_resource(…). and then call json.decode(…) to decode it to Lua tables. The call takes several minutes to complete during which time the game “hangs”.

I’d like to know if I’m doing something obviously wrong or if it’s a known limitation of Defold/Lua.

1 Like

Hi @mtartist !
That sounds like a bug somewhere, not sure what though.
Can you give us a small repro case?

Created a small repro case here maltium/defoldJsonIssue: Repro repo for json issue (github.com)

For what it’s worth, I’m using the Defold version from Steam.

Thank you.

Meanwhile you can also try cjson extension… It took 0.23 ms on your example.

3 Likes

@selimanac Thank you!

I’m not sure what version that is?
Not that I think it matters for this issue.

@Mathias_Westerdahl I think it’s the development version because I get several updates every day.

The about dialog shows version: 1.3.6 and channel is editor-alpha

1 Like

What’s the difference between the built-in JSON module and the cjson extension?

Build-in module doesn’t have json encoding for lua tables.
And also benchmark is here:

3 Likes

Based on those stats, builtin JSON should be moved over to that, and encode can be added while at it.

You can edit the config file in the Defold folder and change “channel = editor-alpha” to “channel = alpha” to get less frequent updates (about every 2 weeks). I think last time the base version on Steam was updated it was set to the editor-alpha one instead of alpha by mistake, editor-alpha means you still are on stable engine version but you get more frequent editor updates. You don’t have to click update every time there is an update / wait for when you know you want a new engine version or are expecting a specific bug fix.

1 Like

We’ll be looking at doing this exact thing during the coming week :+1:

8 Likes

We also have a fix for the slow loading coming up in this PR

4 Likes