Verified Commit 979683c1 authored by Camil Staps's avatar Camil Staps 🚀

Speed up jsDeserialize (again; see 74749311): don't copy at all but overwrite source string

parent 23c58481
Pipeline #24183 failed with stage
in 1 minute and 4 seconds
...@@ -160,10 +160,14 @@ toUIAttributes attr vst ...@@ -160,10 +160,14 @@ toUIAttributes attr vst
# (attr,vst) = serializeForClient attr vst # (attr,vst) = serializeForClient attr vst
= ('Data.Map'.fromList [(JS_ATTR_SVG,JSONString attr)], vst) = ('Data.Map'.fromList [(JS_ATTR_SVG,JSONString attr)], vst)
fromUIAttributes :: !String !*JSWorld -> (!ServerToClientAttr s,!*JSWorld) fromUIAttributes :: !*String !*JSWorld -> (!ServerToClientAttr s,!*JSWorld)
fromUIAttributes json world fromUIAttributes json world
= jsDeserializeGraph json world = jsDeserializeGraph json world
ensure_uniqueness :: !String -> *String
ensure_uniqueness _ = code {
no_op
}
// the server side state: // the server side state:
:: ServerSVGState s :: ServerSVGState s
...@@ -367,7 +371,7 @@ clientGetTaskId me world ...@@ -367,7 +371,7 @@ clientGetTaskId me world
clientInitDOMEl :: !(SVGEditor s v) !JSVal !{!JSVal} !*JSWorld -> *JSWorld | JSONEncode{|*|} s clientInitDOMEl :: !(SVGEditor s v) !JSVal !{!JSVal} !*JSWorld -> *JSWorld | JSONEncode{|*|} s
clientInitDOMEl svglet me args world clientInitDOMEl svglet me args world
#! (model, world) = me .# "attributes.value" .? world #! (model, world) = me .# "attributes.value" .? world
#! (model, world) = jsDeserializeGraph (jsValToString` "" model) world #! (model, world) = jsDeserializeGraph (ensure_uniqueness (jsValToString` "" model)) world
#! (jsView, world) = jsMakeCleanReference (svglet.initView model) me world #! (jsView, world) = jsMakeCleanReference (svglet.initView model) me world
#! (jsModel,world) = jsMakeCleanReference model me world #! (jsModel,world) = jsMakeCleanReference model me world
#! world = (me .# JS_ATTR_VIEW .= jsView) world #! world = (me .# JS_ATTR_VIEW .= jsView) world
...@@ -388,7 +392,7 @@ clientHandleAttributeChange svglet me args world ...@@ -388,7 +392,7 @@ clientHandleAttributeChange svglet me args world
#! world = timeTrace ("clientHandleAttributeChange [" +++ join "," (map fst nv_pairs) +++ "] started at ") world #! world = timeTrace ("clientHandleAttributeChange [" +++ join "," (map fst nv_pairs) +++ "] started at ") world
= case svg_or_text of = case svg_or_text of
Just json Just json
#! (request,world) = fromUIAttributes (jsValToString` "" json) world #! (request,world) = fromUIAttributes (ensure_uniqueness (jsValToString` "" json)) world
= case request of = case request of
(ServerNeedsTextMetrics new_fonts new_texts) (ServerNeedsTextMetrics new_fonts new_texts)
#! world = timeTrace "clientHandleAttributeChange (ServerNeedsTextMetrics) started at " world #! world = timeTrace "clientHandleAttributeChange (ServerNeedsTextMetrics) started at " world
......
...@@ -208,7 +208,7 @@ wrapInitUIFunction :: !(JSVal *JSWorld -> *JSWorld) -> {!JSVal} -> *JSWorld -> * ...@@ -208,7 +208,7 @@ wrapInitUIFunction :: !(JSVal *JSWorld -> *JSWorld) -> {!JSVal} -> *JSWorld -> *
* @param The string to deserialize. * @param The string to deserialize.
* @result The deserialized value. * @result The deserialized value.
*/ */
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld) jsDeserializeGraph :: !*String !*JSWorld -> *(!.a, !*JSWorld)
/** /**
* Load external CSS stylesheet by its URL. * Load external CSS stylesheet by its URL.
......
...@@ -552,10 +552,10 @@ where ...@@ -552,10 +552,10 @@ where
repl_r_args 0 1 repl_r_args 0 1
} }
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld) jsDeserializeGraph :: !*String !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeGraph s w = (deserialize s, w) jsDeserializeGraph s w = (deserialize s, w)
where where
deserialize :: !String -> .a deserialize :: !*String -> .a
deserialize _ = code { deserialize _ = code {
instruction 6 instruction 6
} }
......
...@@ -75,29 +75,11 @@ const ABC={ ...@@ -75,29 +75,11 @@ const ABC={
} }
}, },
deserialize: function (string) { _deserialize: function (addr, size) {
var max_words_needed=string.length/8*4; // rough upper bound
ABC.require_hp(max_words_needed);
var graph;
if (string.constructor.name=='Uint32Array') {
graph=string;
} else if (typeof string=='string') {
var array=new Uint8Array(string.length);
for (var i=0; i<string.length; i++)
array[i]=string.charCodeAt(i);
graph=new Uint32Array(array.buffer);
} else {
throw new ABCError('illegal argument type for ABC.deserialize()');
}
var unused_semispace=ABC.util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
ABC.memory_array[unused_semispace/4+i]=graph[i];
var old_hp=ABC.interpreter.instance.exports.get_hp(); var old_hp=ABC.interpreter.instance.exports.get_hp();
var new_hp=ABC.util.instance.exports.copy_from_string( var new_hp=ABC.util.instance.exports.copy_from_string(
unused_semispace, addr,
graph.length/2, size,
ABC.interpreter.instance.exports.get_asp()+8, ABC.interpreter.instance.exports.get_asp()+8,
ABC.interpreter.instance.exports.get_bsp()-8, ABC.interpreter.instance.exports.get_bsp()-8,
old_hp, old_hp,
...@@ -110,7 +92,28 @@ const ABC={ ...@@ -110,7 +92,28 @@ const ABC={
ABC.interpreter.instance.exports.set_hp_free(new_hp_free); ABC.interpreter.instance.exports.set_hp_free(new_hp_free);
return ABC.memory_array[unused_semispace/4]; return ABC.memory_array[addr/4];
},
deserialize_from_unique_string: function (str_ptr) {
var size=ABC.memory_array[str_ptr/4+2];
ABC.require_hp(size/8*4); // rough upper bound
return ABC._deserialize(str_ptr+16, size/8);
},
deserialize: function (string) {
var max_words_needed=string.length/8*4; // rough upper bound
ABC.require_hp(max_words_needed);
var array=new Uint8Array(string.length);
for (var i=0; i<string.length; i++)
array[i]=string.charCodeAt(i);
var graph=new Uint32Array(array.buffer);
var unused_semispace=ABC.util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
ABC.memory_array[unused_semispace/4+i]=graph[i];
return ABC._deserialize(unused_semispace, graph.length/2);
}, },
interpret: null, interpret: null,
...@@ -493,9 +496,7 @@ ABC.loading_promise=fetch('js/app.pbc').then(function(resp){ ...@@ -493,9 +496,7 @@ ABC.loading_promise=fetch('js/app.pbc').then(function(resp){
break; break;
case 6: /* iTasks.UI.JS.Interface: deserialize */ case 6: /* iTasks.UI.JS.Interface: deserialize */
var hp_ptr=ABC.memory_array[asp/4]; var hp_ptr=ABC.memory_array[asp/4];
var size=ABC.memory_array[hp_ptr/4+2]; ABC.memory_array[asp/4]=ABC.deserialize_from_unique_string(hp_ptr);
var array=new Uint32Array(ABC.memory.buffer,hp_ptr+16,size/4);
ABC.memory_array[asp/4]=ABC.deserialize(array);
break; break;
case 7: /* iTasks.UI.JS.Interface: initialize_client in wrapInitUIFunction */ case 7: /* iTasks.UI.JS.Interface: initialize_client in wrapInitUIFunction */
var array=ABC.memory_array[asp/4]+24; var array=ABC.memory_array[asp/4]+24;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment