Skip to content

Commit d781f35

Browse files
committed
optimize the dioxus implementation and don't leak memory
1 parent 09bb3c0 commit d781f35

File tree

10 files changed

+804
-206
lines changed

10 files changed

+804
-206
lines changed

frameworks/keyed/dioxus/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
dioxus = { version = "0.5.1", features = ["web"] }
9+
dioxus = { git = "https://github.com/ealmloff/dioxus", branch = "restore-comparator" }
10+
dioxus-web = { git = "https://github.com/ealmloff/dioxus", branch = "restore-comparator", default-features = false }
1011
js-sys = "*"
11-
getrandom = { version = "0.2.7", features = ["js"] }
12-
rand = { version = "0.8.5", features = ["small_rng"] }
1312
slab = "0.4.8"
1413

1514
[profile.release]
1615
opt-level = 3
16+
debug = false
1717
lto = true
1818
codegen-units = 1
1919
panic = "abort"
20+
strip = true
21+
incremental = false

frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark.js

Lines changed: 545 additions & 1 deletion
Large diffs are not rendered by default.
Binary file not shown.
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
<!doctype html><html lang=en><meta charset=UTF-8><title>Dioxus</title><link href=/css/currentStyle.css rel=stylesheet><script type=module>import a,*as b from"/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark.js";a(`/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark_bg.wasm`);window.wasmBindings=b</script><link as=fetch crossorigin href=/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark_bg.wasm integrity=sha384-kCFLG6a9WJAnQcYMt5V9KMVnz2xeC2YJWciSvBsA9wGMHbhdSsJmXaNlvBpE29bO rel=preload type=application/wasm><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark.js integrity=sha384-kHpGA-Rs7P9hz5w0RQeGSB5ymMA3EKMg9nE995-GlsZ7UqZTDAotG0-kU4EaZq3C rel=modulepreload><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-4774033abde10986/inline0.js integrity=sha384-GWebH3S-3UMOFt5JciEBc1m8VVbR5C2yPOz8bkQsPloDQacpmH4LRiA-D1GYcCmt rel=modulepreload><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-4774033abde10986/src/js/common.js integrity=sha384-lNXbLTw7Z18z5HtM0HV3R7_8J-II5Ei18I53QeIZolR-l1nGEBr27UjMtT_DJpiC rel=modulepreload><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-51ae765eeff3e7fa/inline0.js integrity=sha384-xqSmg18C2FmchYWi9fb4cSqOW4ZNNo4b7NWZK1eW-fOqg4no-2F-zETwKUf1PJy3 rel=modulepreload><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-51ae765eeff3e7fa/inline1.js integrity=sha384-2v8X0XAeO26J0vmoLhIbIeAjVzFnrY9iLhlYJcksTMp7Ip2tbDcoX4vD_hCan7M7 rel=modulepreload><link crossorigin href=/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-51ae765eeff3e7fa/src/eval.js integrity=sha384-O0D0g9-cXudxTrzdAXYhjXnsL7oWNAzJlU2rv4ODwkbWi11CK6ZE3wz5cPJ3Jh5w rel=modulepreload></head><body><div id=main></div><script src=/frameworks/keyed/dioxus/isKeyed.js></script></body></html>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Dioxus</title>
7+
<link href="/css/currentStyle.css" rel="stylesheet" />
8+
9+
<script type="module" nonce="KnVWZTrvTJq0boMF2kHWww==">
10+
import init, * as bindings from '/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark.js';
11+
const wasm = await init('/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark_bg.wasm');
12+
13+
14+
window.wasmBindings = bindings;
15+
16+
17+
dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));
18+
19+
</script>
20+
21+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark.js" crossorigin=anonymous integrity="sha384-9Ec29d6gQOaxZ6/QYhQkkoUr4sak9s/y7AvVhbmcaLSM+h04tVypwrBGbuFyUxX0">
22+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-90b865b1369c74f4/src/eval.js" crossorigin=anonymous integrity="sha384-O0D0g9+cXudxTrzdAXYhjXnsL7oWNAzJlU2rv4ODwkbWi11CK6ZE3wz5cPJ3Jh5w">
23+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-90b865b1369c74f4/inline1.js" crossorigin=anonymous integrity="sha384-2v8X0XAeO26J0vmoLhIbIeAjVzFnrY9iLhlYJcksTMp7Ip2tbDcoX4vD/hCan7M7">
24+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-9ac3b5e174d5b843/src/js/common.js" crossorigin=anonymous integrity="sha384-lNXbLTw7Z18z5HtM0HV3R7/8J+II5Ei18I53QeIZolR+l1nGEBr27UjMtT/DJpiC">
25+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-9ac3b5e174d5b843/inline0.js" crossorigin=anonymous integrity="sha384-c0QK6eIf5EMBWRdmIkNOCVJRlh7TXHRYQD3CQMa1ML3zFm7Vffwaa7mz2JDcNd1l">
26+
<link rel="modulepreload" href="/frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-web-90b865b1369c74f4/inline0.js" crossorigin=anonymous integrity="sha384-xqSmg18C2FmchYWi9fb4cSqOW4ZNNo4b7NWZK1eW+fOqg4no+2F+zETwKUf1PJy3">
27+
<link rel="preload" href="/frameworks/keyed/dioxus/bundled-dist/dioxus_benchmark_bg.wasm" crossorigin=anonymous integrity="sha384-K7g6QJBA9eu4QD1+MbE6SMwXPcGoSJgPrncf64MSFF/yarYYaUUNKEF5nz3eHG2o" as="fetch" type="application/wasm"></head>
28+
29+
<body>
30+
<div id='main'></div>
31+
32+
<script src="/frameworks/keyed/dioxus/isKeyed.js"></script>
33+
</body>
34+
35+
</html>

frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-4774033abde10986/inline0.js renamed to frameworks/keyed/dioxus/bundled-dist/snippets/dioxus-interpreter-js-9ac3b5e174d5b843/inline0.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
function setAttributeInner(node,field,value,ns){if(ns==="style"){node.style.setProperty(field,value);return}if(ns){node.setAttributeNS(ns,field,value);return}switch(field){case"value":if(node.value!==value)node.value=value;break;case"initial_value":node.defaultValue=value;break;case"checked":node.checked=truthy(value);break;case"initial_checked":node.defaultChecked=truthy(value);break;case"selected":node.selected=truthy(value);break;case"initial_selected":node.defaultSelected=truthy(value);break;case"dangerous_inner_html":node.innerHTML=value;break;default:if(!truthy(value)&&isBoolAttr(field))node.removeAttribute(field);else node.setAttribute(field,value)}}var truthy=function(val){return val==="true"||val===!0},isBoolAttr=function(field){switch(field){case"allowfullscreen":case"allowpaymentrequest":case"async":case"autofocus":case"autoplay":case"checked":case"controls":case"default":case"defer":case"disabled":case"formnovalidate":case"hidden":case"ismap":case"itemscope":case"loop":case"multiple":case"muted":case"nomodule":case"novalidate":case"open":case"playsinline":case"readonly":case"required":case"reversed":case"selected":case"truespeed":case"webkitdirectory":return!0;default:return!1}};class BaseInterpreter{global;local;root;handler;nodes;stack;templates;m;constructor(){}initialize(root,handler=null){if(this.global={},this.local={},this.root=root,this.nodes=[root],this.stack=[root],this.templates={},handler)this.handler=handler}createListener(event_name,element,bubbles){if(bubbles)if(this.global[event_name]===void 0)this.global[event_name]={active:1,callback:this.handler},this.root.addEventListener(event_name,this.handler);else this.global[event_name].active++;else{const id=element.getAttribute("data-dioxus-id");if(!this.local[id])this.local[id]={};element.addEventListener(event_name,this.handler)}}removeListener(element,event_name,bubbles){if(bubbles)this.removeBubblingListener(event_name);else this.removeNonBubblingListener(element,event_name)}removeBubblingListener(event_name){if(this.global[event_name].active--,this.global[event_name].active===0)this.root.removeEventListener(event_name,this.global[event_name].callback),delete this.global[event_name]}removeNonBubblingListener(element,event_name){const id=element.getAttribute("data-dioxus-id");if(delete this.local[id][event_name],Object.keys(this.local[id]).length===0)delete this.local[id];element.removeEventListener(event_name,this.handler)}removeAllNonBubblingListeners(element){const id=element.getAttribute("data-dioxus-id");delete this.local[id]}getNode(id){return this.nodes[id]}appendChildren(id,many){const root=this.nodes[id],els=this.stack.splice(this.stack.length-many);for(let k=0;k<many;k++)root.appendChild(els[k])}loadChild(ptr,len){let node=this.stack[this.stack.length-1],ptr_end=ptr+len;for(;ptr<ptr_end;ptr++){let end=this.m.getUint8(ptr);for(node=node.firstChild;end>0;end--)node=node.nextSibling}return node}saveTemplate(nodes,tmpl_id){this.templates[tmpl_id]=nodes}hydrate(ids){const hydrateNodes=document.querySelectorAll("[data-node-hydration]");for(let i=0;i<hydrateNodes.length;i++){const hydrateNode=hydrateNodes[i],split=hydrateNode.getAttribute("data-node-hydration").split(","),id=ids[parseInt(split[0])];if(this.nodes[id]=hydrateNode,split.length>1){hydrateNode.listening=split.length-1,hydrateNode.setAttribute("data-dioxus-id",id.toString());for(let j=1;j<split.length;j++){const split2=split[j].split(":"),event_name=split2[0],bubbles=split2[1]==="1";this.createListener(event_name,hydrateNode,bubbles)}}}const treeWalker=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT);let currentNode=treeWalker.nextNode();while(currentNode){const split=currentNode.textContent.split("node-id");if(split.length>1)this.nodes[ids[parseInt(split[1])]]=currentNode.nextSibling;currentNode=treeWalker.nextNode()}}setAttributeInner(node,field,value,ns){setAttributeInner(node,field,value,ns)}}export{BaseInterpreter};
33

4-
let bubbles,many,id,field,value,ns;
4+
let field,id,value,ns,many,bubbles;
55
export class RawInterpreter extends BaseInterpreter {
66
constructor(r) {
77
super();
@@ -14,7 +14,7 @@
1414
this.e = null;
1515
this.z = null;
1616
this.metaflags = null;
17-
this.u32buf=null;this.u32bufp=null;this.evt = [];
17+
this.u32buf=null;this.u32bufp=null;this.u16buf=null;this.u16bufp=null;this.evt = [];
1818
this.evt_cache_hit = null;
1919
this.evt_cache_idx;
2020
this.get_evt = function() {
@@ -27,20 +27,20 @@
2727
else{
2828
return this.evt[this.evt_cache_idx&4294967167];
2929
}
30-
};this.ns_cache = [];
31-
this.ns_cache_cache_hit = null;
32-
this.ns_cache_cache_idx;
33-
this.get_ns_cache = function() {
34-
this.ns_cache_cache_idx = this.u8buf[this.u8bufp++];
35-
if(this.ns_cache_cache_idx & 128){
36-
this.ns_cache_cache_hit=this.s.substring(this.sp,this.sp+=this.u8buf[this.u8bufp++]);
37-
this.ns_cache[this.ns_cache_cache_idx&4294967167]=this.ns_cache_cache_hit;
38-
return this.ns_cache_cache_hit;
30+
};this.namespace = [];
31+
this.namespace_cache_hit = null;
32+
this.namespace_cache_idx;
33+
this.get_namespace = function() {
34+
this.namespace_cache_idx = this.u8buf[this.u8bufp++];
35+
if(this.namespace_cache_idx & 128){
36+
this.namespace_cache_hit=this.s.substring(this.sp,this.sp+=this.u8buf[this.u8bufp++]);
37+
this.namespace[this.namespace_cache_idx&4294967167]=this.namespace_cache_hit;
38+
return this.namespace_cache_hit;
3939
}
4040
else{
41-
return this.ns_cache[this.ns_cache_cache_idx&4294967167];
41+
return this.namespace[this.namespace_cache_idx&4294967167];
4242
}
43-
};this.s = "";this.lsp = null;this.sp = null;this.sl = null;this.c = new TextDecoder();this.el = [];
43+
};this.el = [];
4444
this.el_cache_hit = null;
4545
this.el_cache_idx;
4646
this.get_el = function() {
@@ -53,7 +53,7 @@
5353
else{
5454
return this.el[this.el_cache_idx&4294967167];
5555
}
56-
};this.u16buf=null;this.u16bufp=null;this.u8buf=null;this.u8bufp=null;this.attr = [];
56+
};this.attr = [];
5757
this.attr_cache_hit = null;
5858
this.attr_cache_idx;
5959
this.get_attr = function() {
@@ -66,20 +66,20 @@
6666
else{
6767
return this.attr[this.attr_cache_idx&4294967167];
6868
}
69-
};this.namespace = [];
70-
this.namespace_cache_hit = null;
71-
this.namespace_cache_idx;
72-
this.get_namespace = function() {
73-
this.namespace_cache_idx = this.u8buf[this.u8bufp++];
74-
if(this.namespace_cache_idx & 128){
75-
this.namespace_cache_hit=this.s.substring(this.sp,this.sp+=this.u8buf[this.u8bufp++]);
76-
this.namespace[this.namespace_cache_idx&4294967167]=this.namespace_cache_hit;
77-
return this.namespace_cache_hit;
69+
};this.ns_cache = [];
70+
this.ns_cache_cache_hit = null;
71+
this.ns_cache_cache_idx;
72+
this.get_ns_cache = function() {
73+
this.ns_cache_cache_idx = this.u8buf[this.u8bufp++];
74+
if(this.ns_cache_cache_idx & 128){
75+
this.ns_cache_cache_hit=this.s.substring(this.sp,this.sp+=this.u8buf[this.u8bufp++]);
76+
this.ns_cache[this.ns_cache_cache_idx&4294967167]=this.ns_cache_cache_hit;
77+
return this.ns_cache_cache_hit;
7878
}
7979
else{
80-
return this.namespace[this.namespace_cache_idx&4294967167];
80+
return this.ns_cache[this.ns_cache_cache_idx&4294967167];
8181
}
82-
};
82+
};this.u8buf=null;this.u8bufp=null;this.s = "";this.lsp = null;this.sp = null;this.sl = null;this.c = new TextDecoder();
8383
}
8484

8585
update_memory(b){
@@ -96,7 +96,15 @@
9696
this.t = this.m.getUint32(this.d+3*4,true);
9797
this.u32buf=new Uint32Array(this.m.buffer,this.t,((this.m.buffer.byteLength-this.t)-(this.m.buffer.byteLength-this.t)%4)/4);
9898
}
99-
this.u32bufp=0;if (this.metaflags&1){
99+
this.u32bufp=0;if ((this.metaflags>>>4)&1){
100+
this.t = this.m.getUint32(this.d+4*4,true);
101+
this.u16buf=new Uint16Array(this.m.buffer,this.t,((this.m.buffer.byteLength-this.t)-(this.m.buffer.byteLength-this.t)%2)/2);
102+
}
103+
this.u16bufp=0;if ((this.metaflags>>>5)&1){
104+
this.t = this.m.getUint32(this.d+5*4,true);
105+
this.u8buf=new Uint8Array(this.m.buffer,this.t,((this.m.buffer.byteLength-this.t)-(this.m.buffer.byteLength-this.t)%1)/1);
106+
}
107+
this.u8bufp=0;if (this.metaflags&1){
100108
this.lsp = this.m.getUint32(this.d+1*4,true);
101109
}
102110
if ((this.metaflags>>>2)&1) {
@@ -122,15 +130,7 @@
122130
this.s = this.c.decode(new DataView(this.m.buffer, this.lsp, this.sl));
123131
}
124132
}
125-
this.sp=0;if ((this.metaflags>>>4)&1){
126-
this.t = this.m.getUint32(this.d+4*4,true);
127-
this.u16buf=new Uint16Array(this.m.buffer,this.t,((this.m.buffer.byteLength-this.t)-(this.m.buffer.byteLength-this.t)%2)/2);
128-
}
129-
this.u16bufp=0;if ((this.metaflags>>>5)&1){
130-
this.t = this.m.getUint32(this.d+5*4,true);
131-
this.u8buf=new Uint8Array(this.m.buffer,this.t,((this.m.buffer.byteLength-this.t)-(this.m.buffer.byteLength-this.t)%1)/1);
132-
}
133-
this.u8bufp=0;
133+
this.sp=0;
134134
for(;;){
135135
this.op=this.m.getUint32(this.p,true);
136136
this.p+=4;
@@ -163,7 +163,7 @@
163163
break;
164164
}
165165
} else if (ns == "style") {
166-
node.style.removeProperty(name);
166+
node.style.removeProperty(field);
167167
} else {
168168
node.removeAttributeNS(ns, field);
169169
}

0 commit comments

Comments
 (0)