Skip to content

Commit

Permalink
Reduce memory use of cache
Browse files Browse the repository at this point in the history
Improve aivai ui with plies to win, raising max threads to 32
  • Loading branch information
serprex committed Jan 20, 2024
1 parent 1f253a9 commit 19a446d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 40 deletions.
8 changes: 6 additions & 2 deletions aivai.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
input[type="button"],input[type="number"] {
width:49%;
}
#threadspan:after{
content:" threads"
}
#controls {
width:420px;
}
#threads {
width:320px;
width:100%;
margin-top:12px;
}
#replay {
Expand All @@ -40,6 +43,7 @@
<input id="stop" value="Stop" type="button" style="visibility:hidden">
<input id="fight1000" value="Fight!!" type="button">
<input id="limit" type="number" placeholder="Matches">
<div>Threads <input id="threads" value="4" type="range" min="1" max="16"> <span id="threadspan"></span></div>
<span id="threadspan"></span>
<input id="threads" value="4" type="range" min="1" max="32">
<div id="replay"></div>
<div id="result"></div>
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"@pencil.js/spritesheet": "^1.5.1",
"babel-loader": "^9.1.3",
"babel-preset-solid": "^1.8.9",
"copy-webpack-plugin": "^12.0.1",
"copy-webpack-plugin": "^12.0.2",
"html-webpack-plugin": "^5.6.0",
"prettier": "^3.1.1",
"solid-js": "^1.8.10",
"prettier": "^3.2.4",
"solid-js": "^1.8.11",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
Expand Down
6 changes: 3 additions & 3 deletions src/rs/server/src/handleget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub async fn compress_and_cache(
kind: resp.kind,
mtime: mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(),
mtimestring: Some(HttpDate::from(mtime).to_string()),
content: Bytes::from(compressed),
content: Bytes::from(compressed.into_boxed_slice()),
file: resp.file,
};
cache.write().unwrap_or_else(|e| e.into_inner()).get_map_mut(encoding).insert(path, cached_resp.clone());
Expand All @@ -104,7 +104,7 @@ pub async fn compress_and_cache(
kind: resp.kind,
mtime: 0,
mtimestring: None,
content: Bytes::from(content),
content: Bytes::from(content.into_boxed_slice()),
file: resp.file,
},
}
Expand Down Expand Up @@ -189,7 +189,7 @@ impl CachedResponse {
if let Some(ref mtimestring) = self.mtimestring {
builder = builder.header(header::LAST_MODIFIED, mtimestring);
}
builder.body(Bytes::from(self.content.clone()))
builder.body(self.content.clone())
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/ui/aivai.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function fightItOut() {
stop.style.visibility = 'visible';
replay.textContent = '';
let mode = this,
fc = new Uint16Array(4);
fc = new Uint16Array(4),
plysum = 0;
if (mode === fight1000) {
aiWorker = [];
for (let i = 0; i < threads.value; i++) aiWorker.push(new AiWorker());
Expand Down Expand Up @@ -132,18 +133,20 @@ function fightItOut() {
return stopFight();
} else {
fc[(game.winner !== realp1) | (players[0].user << 1)]++;
plysum += game.countPlies();
const p0 = fc[0] + fc[2],
p1 = fc[1] + fc[3];
result.textContent = `${p0} : ${p1} (${((p0 / (p0 + p1)) * 100).toFixed(
p1 = fc[1] + fc[3],
p01 = p0 + p1;
result.textContent = `${p0} : ${p1} (${((p0 / p01) * 100).toFixed(
2,
)}%)\nWith coin ${fc[0]} : ${fc[1]} (${(
)}%) ${(plysum / p01).toFixed(2)}ptw\nWith coin ${fc[0]} : ${fc[1]} (${(
(fc[0] / (fc[0] + fc[1])) *
100
).toFixed(2)}%)\nWithout ${fc[2]} : ${fc[3]} (${(
(fc[2] / (fc[2] + fc[3])) *
100
).toFixed(2)}%)`;
if (limit.value && limit.value <= p0 + p1) {
if (limit.value && limit.value <= p01) {
return stopFight();
}
}
Expand Down

0 comments on commit 19a446d

Please sign in to comment.