working on fourth demo

This commit is contained in:
Pagwin 2025-08-25 16:37:29 -04:00
parent bfc926c473
commit 2c0b439366
2 changed files with 54 additions and 2 deletions

View file

@ -156,7 +156,7 @@ looks good at first glance(actual version code quality is bad but blog version s
<video width="700" height="400" controls src="/static/video/frac_gen_v2.mp4"></video>
Oh... we run out of memory... or well we run out of 30 gigabytes of memory because I set a limit to avoid effecting the other stuff running on the server(because it isn't mine). But why? Doing the math if all we had to deal with was the fractions we'd be using about `17501876*4/1000**3 ~ 0.07 GB`, if we include the overhead of all the Vecs we make and are pretty agressive with how much memory they use maybe 0.21 GB which is a difference of over 142x. So what's the rest of the memory?
Oh... we run out of memory... or well we run out of 30 gigabytes of memory because I set a limit to avoid affecting the other stuff running on the server(because it isn't mine). But why? Doing the math if all we had to deal with was the fractions we'd be using about `17501876*4/1000**3 ~ 0.07 GB`, if we include the overhead of all the Vecs we make and are pretty agressive with how much memory they use maybe 0.21 GB which is a difference of over 142x. So what's the rest of the memory?
Well... I'm not 100% sure actually but my current best guess is the green threads/tokio tasks. Whatever it is on average it seems to have memory usage measured in hundreds of bytes and/or a kilobyte or 2 roughly doing a bit of quick math(I just divided 30GB/num_of_running_tasks). So I guess I gotta take out the green thread usage huh.

View file

@ -2,7 +2,7 @@
self.addEventListener("fetch", event =>{
//TODO: make an endpoint to set the localStorage up then set the form to go to there and have it HTTP 302 or 307
//TODO: make an endpoint to set the localStorage up then set the form to go to there and have it HTTP 302 or 307 with handle_html for html responses and handle_redirect for the other case
event.respondWith((async ()=>{
const resp = await fetch(event.request);
const body = await resp.text();
@ -12,3 +12,55 @@ self.addEventListener("fetch", event =>{
});
})());
})
async function handle_redirect(req){
const go_back_to = req.referrer;
const db_req = self.indexedDB.open("light-dark-store");
const up_promise = new Promise((res)=>{
db_req.onupgradeneeded = (event) => {
const db = event.target.result;
await IDB_cond_create(db, "light-dark-store", {});
res();
}
};
const suc_promise = new Promise((res)=>{
db_req.onsuccess = (event) => {
const db = event.target.result;
const transaction = db.transaction("light-dark-store");
transaction.oncomplete = res;
transaction.objectStore("light-dark-store", "readwrite");
toggleLightDark(transaction);
transaction.commit();
};
};
await Promise.all([up_promise, suc_promise])
}
function IDB_cond_create(db, objectStoreName, opts={}){
return new Promise((res)=>{
if(!db.objectStoreNames.contains(objectStoreName)){
db.createObjectStore(objectStoreName, opts);
res();
});
}
function toggleLightDark(transaction){
return new Promise((res)=>{
const obj_store = transaction.objectStore("light-dark-store");
const grab = obj_store.get(1);
grab.onsuccess = (event)=>{
const val = event.result;
if(val){
const yeet = obj_store.delete(1);
yeet.onsuccess = res;
}
else {
const plonk = obj_store.add({id:1});
plonk.onsuccess = res;
}
}
});
}
async function handle_html(req){
// TODO: read from indexDB to figure out if we fiddle with the body classes or not
}