apollographql / persistgraphql

A build tool for GraphQL projects.
MIT License
425 stars 57 forks source link

[Idea] replace json property names with ordinals to reduce bandwidth #47

Open dcworldwide opened 7 years ago

dcworldwide commented 7 years ago

Just a thought, so we already have query -> id mapping. Would it then not be possible to extend that concept to the JSON payload property names?

I.e.

{
   orders: [
       id: "",
       customer: {...}
   ]
}

to

{
   1: [
       2: "",
       3: {...}
   ]
}

and then have apollo restore the property names?

Poincare commented 7 years ago

Does this result in a significant reduction in bundle size post-gzipping?

dcworldwide commented 7 years ago

Will test tomorrow. Presumably largest benefit would be for non gzip responses

teakesdev commented 7 years ago

Interesting Idea. I will give it a try on Monday.

dcworldwide commented 6 years ago

A quick and dirty test on a large json file that I had.

json size test

output.json is a large json array with redundant keys output.optimised.json re-names all keys from strings, into single/double character pseudo keys (as per OP)

This was a large file test, so the relative % difference is probably more relevant. Per request it's probably not too big a deal, but if your server needs to handle high throughput, this could make sense..