ceylon / ceylon-js

DEPRECATED
Apache License 2.0
54 stars 9 forks source link

optimize model for homogeneous tuple types #580

Closed gavinking closed 9 years ago

gavinking commented 9 years ago

Given this code:

Null[1k] null = nothing;

I get:

java.lang.StackOverflowError
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:493)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:169)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:491)
    at net.minidev.json.JSONArray.writeJSONString(JSONArray.java:88)

I assume this is because the model serializer tries to walk the whole tuple linked list. That's not necessary for a type like Null[1k] which can just be stored as an element type and a length.

In general, I think you should look into optimizing how tuple and sequence types are serialized to the model.js.

chochos commented 9 years ago

Null[1k] wasn't that some experimental feature?

chochos commented 9 years ago

Is there anything in ModelUtils or anywhere else I can use to determine that a tuple is just a fixed-size collection of elements of the same type? I know there's something to get the list of tuple element types, but I haven't used it because that's only useful for encoding in the model, I haven't found if there's already something for decoding...

gavinking commented 9 years ago

@chochos I have Unit.isHomogeneousTuple() and Unit.getHomogeneousTupleLength().

chochos commented 9 years ago

Ah, didn't see them. I'll use those instead.

tombentley commented 9 years ago

Null[1k] wasn't that some experimental feature?

Well I can't find it mentioned in the spec. Maybe I'm being blind @gavinking?

gavinking commented 9 years ago

§3.2.8

X[1] means [X], for any type X, and X[n] means Tuple<X,X,X[n-1]> for any type X and positive integer n.