Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize Huge JSON response

I am working on a Big Data client side application. Server language is Java. Within Frontend I have heavily vanilla JavaScript but AngularJS as MVC framework.

Problem

Dealing with big data analysis, at a time a single REST api response is around 1.5MB to 3MB. Dealing with this data to construct DOM is a pain.

  • First it takes around 5 to 10 seconds to load the JSON.
  • Then I build the UI (DOM)
  • Once DOM is constructed, based on users interaction with data - I have to send/hit the server back with same JSON with updated values.

Suggest, What are the options do I have to optimize the page responsiveness"

  • Couple of things I have in mind:
  • break the JSON into chunks of 1000 at a time, once DOM is loaded then bring data silently and update the UI.
  • GZIP the JSON on the server and decode back on client.

Give me your concrete workarounds!

Sample JSON could be:

var data = [
    {
        prop:val,
        prop2: {},
        prop3:[
            id: val,
            prop4: { {}, {}, {}, {}},
            prop5: [ [], [], [] ]
        ]
    },
    {},
    {},
    {}
]

Some Use cases

  • DATA size could be 10000 of objects, nested at a minimum of six, seven deep levels.
  • Need to construct grid (table), rows goes around same length as objects and columns at minimum of 100 columns.
  • All data cells have custom context menu, have nested headers, all columns to be sortable, rows to be sortalbes and these sorted orders hits the server as soon as users changes that. But I do have a second of threshold.

A very basic example is here: http://shekhardesigner.github.io/OuchGrid/

like image 662
Shekhar K. Sharma Avatar asked Nov 11 '14 11:11

Shekhar K. Sharma


People also ask

How big is too big for a JSON response?

One of the more frequently asked questions about the native JSON data type, is what size can a JSON document be. The short answer is that the maximum size is 1GB. However, JSON often changes how data modeling is done, and deserves a slightly longer response.

How do I reduce the size of a JSON file?

How do you use the JSON Minifier tool? Enter your JSON text or file into the first text area above, the JSON text will be automatically minify in the output text area, easily minify any JSON text fast and free.

Can JSON response be compressed?

JSON responses are not natively compressed. Response compression can optimize network bandwidth usage and increase application responsiveness.


1 Answers

some of my advice:

  1. paginate your response data from serverside first to reduce the size of the json object.
  2. parallel render then ui by chunk
  3. don't do deep watch in the data if the data is too big, for example don't ngRepeat for too many data, if two way binding is not nessary. that will make your application very slow
like image 124
Sean Avatar answered Sep 19 '22 20:09

Sean