1

I'm just wondering if d3.text is faster than d3.json?

The reason behind my question is that I'm reading the source code behind cubism.js and I'm just curious to know if it's done with d3.text because it's faster?

VividD
  • 10,456
  • 6
  • 64
  • 111

1 Answers1

4

Not really.

The reason the graphic metric uses d3.text is because Graphite doesn’t reply with JSON-formatted data; it has its own raw format. Cubism does use d3.json when the server replies with JSON, as for example with cube metrics.

Under the hood, both d3.text and d3.json both use d3.xhr, so they are going to download the file exactly the same way (via asynchronous XMLHttpRequest). Sure, d3.text doesn’t subsequently run the response through JSON.parse, but you still have to parse the reply somehow. And more often than not I would expect the native JSON.parse to be faster, though it would depend on the exact format.

mbostock
  • 51,423
  • 13
  • 175
  • 129
  • Thanks!!! actually graphite replies with json now. format=json. and the reason why I'm asking is because I have 43*5 different metrics and we're facing the browser connections limit. I'm currently trying to load each of the 43 in one batch and I'm following how you're parsing the data. –  Aug 09 '13 at 00:13
  • I think as far as Graphite is concerned specifically, the raw format was much more efficient than the JSON format, which is why the raw format is used with Cubism. So perhaps that’s a more direct answer to your question. :) – mbostock Aug 09 '13 at 03:22