Reputation: 1037
I am using the javascript library JQGrid to show a list of results. I want to squeeze out every last bit of performance gain I can. I am using the JQGrid url property to call a ASP.NET MVC ActionMethod.
In the action method I do my query then load an anonymous object with 3 int properties and 1 collection property:
public JsonResult GetDataRows(int dataId)
{
IEnumerable myDataCollection = linqDB.DataRows.Where(i => i == dataId);
var data = new
{
page = 1,
total = 1,
records = 3,
rows = myDataCollection.ToList();
};
return Json(data, JsonRequestBehavior.AllowGet);
}
Is the MVC Json method the fastest way to serialize this data back to the javascript client script? Is there something faster.
Upvotes: 0
Views: 813
Reputation: 1037
I had a look under the covers of the MVC framework and it looks like behind the JSON helper is the JavascriptSerializer. While doing some testing I hit the maximum payload.
Since we already had the Newtonsoft JSON.NET library I added a custom ActionResult using its serializer. Just using it to write to the browser not using it to serialise any JSON input...yet that is. Here is the link to the ActionResult override to use the alternative serialiser.
Although this serializer is apparently faster than the standard ones, the fact that Microsoft WebAPI uses JSON.NET made me think this future proofs this one. However based on my searching the web and readings, it sounds like the ServiceStack.Text serializer is the best. Which apparently derives from the ProtoBuf-net serializer.
Upvotes: 1