At the moment I have written an http server and JSON parser. When user requests data, raw data from memory are read and parsed into JSON for sanding. Parsing raw data into text json result in extending each 1MB (of raw) into about 2MB (of text).
Local browser waits for JSON file and using JS JSON.parse(this.responseText) parses it into object for adding into an javascript array.
JSON.parse tooks lots of time! About 5 sec for each 2MB (1MB of raw).
Code: Select all
function loadChartData(address) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = loadChartDataReady;
xhttp.open("GET", "http://192.168.1.1/"+address, true);
xhttp.send();
}
function loadChartDataReady() {
if (this.readyState != 4) return;
if (this.status != 200) { return; }
try {
var json = JSON.parse(this.responseText);
for(var i = 1; i < json.length; i++) {
var obj = json[i];
series.splice(i - 1, 0, {ts: obj[0], time: obj[1], s: obj[2], m: obj[3], on: obj[4]} );
}
updateChart();
} catch(err) {
console.log("error: " + err);
}
}
- Can I parse raw data somehow in javascript?
- Can I change JSON.parse into some another function for speeding up?
- Can I change XMLHttpRequest into something another for start parsing data while they are still being sent?