Vorganger / Elden-Equip

MIT License
4 stars 1 forks source link

browser.executeJavaScript optimization #1

Closed Pospelove closed 1 year ago

Pospelove commented 1 year ago

Hey! Thanks for making this mod, it's one of the most popular (if not the most) in the SkyrimPlatform field

I came up with the idea of optimizing executeJavaScript calls as each of them is pretty heavy and requires IPC between SkyrimSE.exe and Chromium.

Let's batch those calls every frame and perform only 1 call per frame.

Possible implementation: https://github.com/Vorganger/Elden-Equip/blob/main/src/widget.ts

let buffer = "";

function myExecuteJavaScript(script: string) {
  buffer += string;
}

on("tick", () => {
  const copy = buffer;
  buffer = "";
  browser.executeJavaScript(copy);
});

Thank you in advance!

Vorganger commented 1 year ago

You're welcome, and thanks for creating SkyrimPlatform since it made developing mods easier despite its quirks.

I tried out your optimization since it seemed good in theory. However, I noticed longer buffers did not make any changes to the widget. I tried splitting the buffer by a semicolon and building a shorter temporary buffer which is passed into browser.executeJavaScript() to find out that more widget elements were being updated (which is good) but some did not (which is not good).

Overall, since the performance gain seems to be negligible or probably nonexistent, I am not gonna use this optimization. I would instead want to make optimizations that have a significant effect and do not compromise functionality.