aritter on Nostr: It was just a very simple getting https requests from the browser vs sending ws ...
It was just a very simple getting https requests from the browser vs sending ws messages, and WebSocket / Nostr won by 10x. Maybe working more on HTTP/3.0 support would speed things up and allow better caching, but it's probably just not worth it, as it's getting farther from the original Nostr protocol:
w=new WebSocket("wss://rbr.bio"); w.onopen=()=>console.log("opened"); w.onmessage=(x)=>console.log("message", x)
z=0;all=1000;time=Date.now();w.onmessage=(x)=>{if(JSON.parse(x.data)[0]=="EVENT") z++; if(z==all) console.log("time",Date.now()-time) }; for(i=0;i<all;i++) w.send('["REQ","1",{"authors":["82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2"],"kinds":[0]}]')
// 2500ms
let u="
https://rbr.bio/82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2/metadata.json";
time=Date.now(); a=[];for(i=0; i<1000; i++) a.push(fetch(u)); for(i=0; i<a.length; i++) await a[i]; console.log(Date.now()-time)
// 21035ms
Also tested JSON.parse:
time=Date.now();for(i=0; i<1000; i++) JSON.parse(data);Date.now()-time
// 2ms
Published at
2023-03-12 21:53:17Event JSON
{
"id": "405e08eb1bee8181a38c9414b56b5865a004360cf6801308cb1df8798a0ff887",
"pubkey": "6e3f51664e19e082df5217fd4492bb96907405a0b27028671dd7f297b688608c",
"created_at": 1678657997,
"kind": 1,
"tags": [
[
"e",
"1bcd3847374afe0ea1b5ea4e5d5bea5e1cbdfd3042abc677cb866f8551f3ab37",
"",
"root"
],
[
"e",
"26bdeea0c65e0fddc74aedc1b92aa8d6ace66fbcd66b66ade8899ea7daf9ad14",
"",
"reply"
],
[
"p",
"6e3f51664e19e082df5217fd4492bb96907405a0b27028671dd7f297b688608c"
],
[
"p",
"126103bfddc8df256b6e0abfd7f3797c80dcc4ea88f7c2f87dd4104220b4d65f"
]
],
"content": "It was just a very simple getting https requests from the browser vs sending ws messages, and WebSocket / Nostr won by 10x. Maybe working more on HTTP/3.0 support would speed things up and allow better caching, but it's probably just not worth it, as it's getting farther from the original Nostr protocol:\n\nw=new WebSocket(\"wss://rbr.bio\"); w.onopen=()=\u003econsole.log(\"opened\"); w.onmessage=(x)=\u003econsole.log(\"message\", x)\nz=0;all=1000;time=Date.now();w.onmessage=(x)=\u003e{if(JSON.parse(x.data)[0]==\"EVENT\") z++; if(z==all) console.log(\"time\",Date.now()-time) }; for(i=0;i\u003call;i++) w.send('[\"REQ\",\"1\",{\"authors\":[\"82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2\"],\"kinds\":[0]}]')\n// 2500ms\nlet u=\"https://rbr.bio/82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2/metadata.json\"\ntime=Date.now(); a=[];for(i=0; i\u003c1000; i++) a.push(fetch(u)); for(i=0; i\u003ca.length; i++) await a[i]; console.log(Date.now()-time)\n// 21035ms\n\nAlso tested JSON.parse:\ntime=Date.now();for(i=0; i\u003c1000; i++) JSON.parse(data);Date.now()-time\n// 2ms\n",
"sig": "f0d1bfb6b42d64cc51a7361c74279743bbc8f789e202ed3d840c6bfc44897c6879d6f8fa502d1bd087b00b2a73da7be773d3f9703a08a1eb2557aabce7ea572b"
}