Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose loadBundle and loadBundleFromFile in player-api-load.ts to the public API #365

Open
ruochenjia opened this issue Jan 14, 2025 · 4 comments

Comments

@ruochenjia
Copy link

Currently the only way to load a bundle from a ArrayBuffer object is through the use of blob URL. However this can cause memory leaks especially for large game files. Blob URLs created by URL.createObjectURL are duplicated from the original ArrayBuffer and stored in memory until URL.revokeObjectURL is invoked.

The workaround I used at this moment:

const url = URL.createObjectURL(new Blob([arrayBuffer], { type: "application/octet-stream", endings: "native" }));

Dos(frame, {
	onEvent: (e) => {
		if (e === "emu-ready")
			URL.revokeObjectURL(url);
	},
	url: url,
	theme: "light",
	...
});
@caiiiycuk
Copy link
Owner

But how you get this big array buffer? You downloaded it manually and then pass it to DOS? I mean you could just pass URL to DOS. Also I am not sure that blob will create a copy of array buffer, probably it will copy on write or something similar. Anyway even if it do a copy the memory consumption will grow only if you keep reference on original array buffer.

Memory consumption is a hard topic, if you really want to reduce memory usage you should use sockdrive or pass game files one by one to emulator

@caiiiycuk
Copy link
Owner

Another point, the save/load mechanism will work correctly only when you pass an URL. Csuse URL is used as a key to lookup saves

@ruochenjia
Copy link
Author

I am working on a web app that uses the cache and service worker API that allows it to be used when offline. Game are downloaded once and stored locally with indexedDB, so it becomes ArrayBuffer when accessed. Supporting loading from ArrayBuffer directly will make the loading process more efficient, as it avoids calling and awaiting fetch.

For the save/load mechanism to work, it is possible to use a sha256 checksum of the ArrayBuffer as a key, or enforce users to specify a custom key, or use the current page's URL.

@caiiiycuk
Copy link
Owner

Just to let you know, js-dos already do this. It stores downloaded bundle in indexed db, so it will not be downloaded again while indexeddb is live.

изображение

I still think is better to use default js-dos integration, cause I always improve it. Anyway this is valid request, we can expose such api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants