-4

I'm currently developing an reporting application to compare multiple tests. I need to pass a json object from controller to client side to draw all these charts for the report. I attach here the images of the result I got when I compared just 2 tests. The data passed is ~600kb, time ~ 3seconds. Here is the code I use in controller:

var jsonResult = Json(new
{
  ReportData = reportData
}, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = Int32.MaxValue;
return jsonResult;

How can I improve my application's performance? Any suggestions are greatly appreciated.

Ps: If my question is not appropriate for the standard here, please bing me so I can adjust it. For all has downvoted, please comment so I can improve next time. Thanks ton

enter image description here

MinhNguyen
  • 816
  • 1
  • 11
  • 26
  • 4
    You've got to ask yourself, is all of this data needed? A slimmer and potentially less verbose DTO may be in order. – Zachary Dow Nov 30 '15 at 20:09
  • I have to pass that amount of data. Your comment does not help at all – MinhNguyen Nov 30 '15 at 20:26
  • 2
    @MinhNguyen It may not have helped *in this case* but it is definitely a valid question to ask. Perhaps you should note in the question that all of the data is required and that none of it can be left out. – mason Nov 30 '15 at 20:31
  • 1
    Even though you say you can't strip any of the properties out of the json because you need it all, that still isn't accounting for trimming down the property names. For example, 80 instances of `MyObjectBusinessLevelHandlerName` could be cut to `moblhName` and save quite a few bytes... Saying that you can't reduce the data packet across the board is probably wrong. – Zachary Dow Nov 30 '15 at 20:36

1 Answers1

2

You should drill down inside those 3 seconds in order to determine where are exactly they lost. There are lots of things happening here:

  1. You are building this reportData variable from somewhere - measure how long it takes
  2. You are serializing this reportData variable into JSON - measure how long it takes

Once you have those measurements you will know where you need/can optimize. If it turns out that 2.9s out of 3s are lost in 1. then you definitely should improve the way you are querying your data or maybe optimize your data store (pretty hard and subjective thing to talk about assuming the information you provided so far). Maybe you just forgot to add an index to some column in your SQL database - who knows.

If on the other hand it turns out that your bottleneck is 2. then you definitely have a HUGE design problem. Usually the serialization is not an issue unless you are doing something very wrong, like trying to serialize enormous amounts of data that nobody ever needs or a human being can consume. In this case of course you should be talking to the UI guys that invented the screens you are implementing and explain to them that it hardly makes sense to display 1 million points on a screen with resolution 1024x768 (just an example) and then of course improve your query so that your view model is not that insanely huge.

So bottom line is that you should be narrowing down where this time is lost (using a profiler is a very good start, I would recommend you Telerik's JustTrace) so that you know exactly where you need to improve.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks @Darin for your constructive comment. As you can see I'm not really experienced with dealing Json object here. So this particular case, when the response is ~600kb, is this considered enormous amount of data? For the UI side, I would not pass more than 100k points at once, is that still too big? – MinhNguyen Nov 30 '15 at 20:25
  • It will very much depend on what you are trying to achieve and how you are displaying your data. Once again I very strongly encourage you to drill down into those figures so that you know whether the time is wasted into querying your data or serializing it to JSON. Once you've got those figures you will be able to pinpoint the exact location of the problem and ask much more constructive questions. – Darin Dimitrov Nov 30 '15 at 20:27
  • I'm using JustTrace, most of the consuming time comes from the two methods: System.Threading.WaitHandle.WaitOne(...) and System.Threading.Thread.Sleep(). What do you think the cause of this? Thank alot for your help so far – MinhNguyen Nov 30 '15 at 20:56