I'm using GWT to build an application, and I'm facing serious speed issues with something that I thought would be pretty fast. I have a JSONObject with data in the following structure (but that is much larger):
{"nodeData" : [
{ "name":"one", "attributes":["uno","dos"]},
{"name":"two", "attributes":["tres"]}
]
}
I am trying to iterate through the JSON object to store all the attributes into an arraylist which every node object has, with attribute sizes ranging from 4 to 800.
JSONObject JSONnode = nodeData.get(i).isObject();
Node node = new Node(JSONnode.get("name").toString();
JSONArray attributeArray = JSONnode.get("Attributes").isArray();
int attributeSize = attributeArray.size();
for(int j = 0; k < attributeSize; j++){
node.attributeArrayList.add(attributeArray.get(j).toString();
}
The for loop I'm executing is taking about a minute, which seems too long, and I'm not sure how to improve it. The minute is in development mode, but I don't know if it would be any faster when I compile it.
Have you tried using overlays?
GWT Coding Basics - JavaScript Overlay Types
You can create overlay types pretty easily:-
// An overlay type
class Customer extends JavaScriptObject {
// Overlay types always have protected, zero-arg ctors
protected Customer() { }
// Typically, methods on overlay types are JSNI
public final native String getFirstName() /*-{ return this.FirstName; }-*/;
public final native String getLastName() /*-{ return this.LastName; }-*/;
// Note, though, that methods aren't required to be JSNI
public final String getFullName() {
return getFirstName() + " " + getLastName();
}
}
Very easy to use and I think would be much faster than using JSONObject objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With