CPU Usage Issue

May 19, 2011 at 11:54 AM

Hello all,

I was in the middle of evaluating datajs 0.0.3 when I stumbled onto this this problem: whenever I use the cache object (without the prefetching option set), each time I call the readRange function, the CPU usage rises on the client machine until it reaches 100% and stays there. This happens no matter what browser I use (IE9, Mozilla or Chrome).

The details:

On the server side, I created a WCF Data Service that looks like this:

public class DataService : DataService<ODataContext>
   // This method is called only once to initialize service-wide policies.
   public static void InitializeService(DataServiceConfiguration config)
       config.SetEntitySetAccessRule("Documents", EntitySetRights.AllRead);
       config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;


The ODataContext class looks like this:

public class ODataContext
   List<Document2> _docs;
   public IQueryable<Document2> Documents
           return _docs.AsQueryable();
   //some other initialization code


The Document2 class is a simple class that exposes two properties, ID and Name.

On the client side, the HTML looks like this:

     <ul id="here">
     <a href="#" onclick="javascript:loadMoreData();">Next</a>
<script type="text/x-jquerytemplate" id="listTemplate">
   <li><b>ID: ${ID}</b> - ${Name}</li>
<script language="javascript" type="text/javascript">
     var cache = datajs.createDataCache({
       name: "data",
       source: "DataService.svc/Documents",
     var index = 0;
     function loadMoreData() {
        cache.readRange(index, 10).then(function (arr) {
          index += 10;


 As you see, pretty basic code. After some profiling, it turns out that the majority of the CPU time is spent in this anonymous function from datajs-0.0.3.js (line 4469):

// Hydrate using json

value = window.JSON.parse(value, function (k, v) {

Am I doing something wrong? Did anyone else encounter this behavior ?

Any help would be greatly appreciated.


May 19, 2011 at 7:02 PM

Hi Radu,

I believe we had a bug in datajs 0.0.3 which caused some overzealous prefetching. Alex has checked in some pretty significant changes to the cache implementation since then. Could you try using the latest bits from change set 7294 and let us know if you still see the issue?


May 24, 2011 at 7:51 AM

Hi Beth,

The issue has been fixed in this change set.

Thank you very much for your help.