Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Use Gson to convert javaObject to jsObject #324

Merged
merged 3 commits into from
Mar 23, 2017

Conversation

SBD580
Copy link

@SBD580 SBD580 commented Mar 22, 2017

Hi,

We had major performance issues with the plugin when working with medium json files (>50K). It took a couple of seconds (5-8 seconds) to convert the javaObject to javascript one, and it was done twice instead of just one time.

Using Gson (any other library will due I guees) with JSON.parse it take only several (200-300) milliseconds.

This has not tested fully yet and maybe it should be configurable (maybe its having a performance issue on a small size files).

Would like to know why in the first place the conversion was done this way and not with some standard library.

Shay

@EddyVerbruggen
Copy link
Owner

Thank you! I'll look at it (hopefully) soon.

The reason it is what it is, is because of this. Never gave it a second thought to do it differently but your suggestions makes much sense.

@SBD580
Copy link
Author

SBD580 commented Mar 22, 2017

I see. BTW looking at the gist, the last comment there suggest something similar.

Give it a look, I'm sure things can do better. And maybe iOS support?

@EddyVerbruggen
Copy link
Owner

I may have tried that and had issues, so beware. I use Gson all the time when working on serverside Java so I'm sure your suggestion will be pretty good.

We could also take a look at {N}'s http module source.

@SBD580
Copy link
Author

SBD580 commented Mar 22, 2017

I believe things here a bit different - we are not just parsing JSON string, but we need to transform the DataSnapshot Java object back to JSON string and then parsing it (for some reason, Firebase Andrioid library designers chose not to expose the raw data like they did for example for their Unity library, things could have been even faster that way)

@EddyVerbruggen EddyVerbruggen merged commit b9ff3d6 into EddyVerbruggen:master Mar 23, 2017
EddyVerbruggen pushed a commit that referenced this pull request Mar 23, 2017
@EddyVerbruggen
Copy link
Owner

This seems to work really well. I only test with small data structures so don't notice a speed difference, but the conversion looks spot on. Perhaps even fixes an issue or two..

I've added some fallback code in case users updating the plugin don't automatically pull in Gson. But that's a temporary state of course. Just don't feel like a bunch of issues where folks report com.google.gson.Gson is undefined.

@EddyVerbruggen EddyVerbruggen added this to the 3.11.1 milestone Mar 23, 2017
@SBD580
Copy link
Author

SBD580 commented Mar 23, 2017

Sounds good :)

EddyVerbruggen added a commit that referenced this pull request Apr 18, 2017
Use Gson to convert javaObject to jsObject
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants