-
Notifications
You must be signed in to change notification settings - Fork 50
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
[cubing.js issue] Unable to generate screenshots simultaneously #359
Comments
Since you made your function await screenshot({ alg: "R", imgId: "screenshot-1" });
await screenshot({ alg: "F", imgId: "screenshot-2" }); As conveyed by the function signature and name, this is an async screenshot feature that is also experimental. 😛 It is theoretically possible for us to offer a version of this with different semantics, but that comes with its own complications and compromises. So |
This bug is specifically for the case of generating screenshots asynchronous . I'm reproducing a more complex scenario that I can't await on (rendering Svelte components).
I'm using a |
Ah, Svelte strikes again! I assume this is for SSR? I'd definitely like to enable that. If you can't await in Svelte, though, how are you able to take screenshots there at all? It would definitely be good to have a repro for that.
Ah, yeah, they're the same thing. So I refer to them interchangeably, sorry. 😅 |
I'm not doing SSR. This issue also isn't Svelte-specific. The HTML provided in the issue is a static HTML file you can open directly in the browser to see the bug. I've updated the code to include the html/body tag to make it more clear.
The code does a |
Ah, I see. If you need lots of actual screenshots images, then the correct solution is definitely to However, I'm still a bit unclear on your use case — why do you need the screenshots? If they're being shown to visualize e.g. cases on a page, you should be able to create hundreds or thousands of players on a page with reasonable efficiency. |
Is this the intended behavior of screenshots? Seems strange that one player would influence the screenshot from another player. If it's intentional perhaps worth documenting.
Glad to know hundreds of players on one page will be efficient. The use case being I want to display a static cube image and am currently using a player for each case. I wanted to generate a screenshot and cache it locally so it will be more efficient on future loads (no need to even use a player). Each player is in its own svelte component so each one renders asynchronously. This is why it's difficult to I think in the long-run I'll create an SVG template and swap out the colors based on the end state of a given algorithm. That would be most efficient. I'm uncertain if Thanks for your work on this project! |
Yes.
That should definitely not be happening. If you run into that, please do let us know!
Yeah, our architecture is designed for this. There's more room to optimize, but this issue motivated me finally implement the most low-hanging fruit: 34836d6
Hmm, have you fully modeled situations where this would be beneficial? I would definitely see the benefit of being able to show something useful even when JavaScript is not working (and this is something I want to have good tools for in the future1), but by far the most robust and efficient way to achieve that is either SSR or rendering the images at site deployment time.
Yeah, a global queue would work. At that point, though, you're actually doing the same as each player does under the hood. The first two players on a page have their own exclusive rendering context, but all the others actually reuse the same shared rendering context. So they are actually queueing to generate screenshots using the exact same mechanism as In theory there could be a benefit to reducing the overhead each player element, e.g. if somehow you really needed to minimize the size of the DOM tree, or if the alg representations/puzzle states were all too large to keep in memory at once. But I think it would have to be a pretty extreme situation where this is a bottleneck (and I'd definitely love to know of such a real-world example if there is one). If you're planning on caching or loading the images I'd also encourage you to make some measurements. The entire ZBLL page loads over the network in 248kB over the wire (973kB once uncompressed) across 4 files. A single 200×200 screenshot is 40kB (uncompressed base 64 when returned from
Yeah, if you use 2D SVG visualization then you could Footnotes
|
Thanks for the detailed response.
It is happening for asynchronous screenshots. Two players are created. Try saving the HTML at the top of the issue and opening in a browser. ![]()
I was considering storing it in IndexedDB which has higher storage limits. The optimization is less about bandwidth and more about client-side performance once the app has loaded. However since TwistyPlayer is so efficient I don't know if it's worth it. I haven't done any profiling. I'll probably skip this and jump to the SVG approach eventually.
I'm looking for a 3D representation. Something like https://github.com/tdecker91/visualcube It's not priority for my project so I haven't looked into this yet. |
Right, that's a different thing. (You're taking two screenshots of a single player at the same time.)
Oh, interesting. If this is something you can get good perf with, that would certainly be cool
Yeah, any of those SVGs should be compatible! |
Sorry to persist on this issue. But why is this a different thing? Why is creating two separate instances of |
Ah, I'm so sorry. 😳 I specifically remember designing something to prevent this issue, so I thought it couldn't be happening with multiple players and misread your code. (It also didn't make sense to me that you would specifically intend to use multiple players for this, as that couldn't help with performance. But I guess that only makes sense to me because I know the implementation. 🤦) But yeah, for some reason that code's not in place. Even if it's marked as experimental this would be nice to clean up. It seems there are now some more ecosystem options for this, I'll take a look and land some sort of stopgap as soon as I can so that you can at least screenshot multiple players in parallel. |
@lgarron Thanks! Don't rush a fix on my account. Since you've made the player so efficient I don't know if it's worth doing the screenshot optimization anyway. |
Steps to reproduce the issue
I get the same screenshot when I try to generate multiple ones simultaneously. Here's some HTML.
Both screenshots look the same matching the last twisty player alg. If I add
await screenshot(...)
then it generates them correctly. Perhaps there's some global shared state in.experimentalScreenshot
?Observed behaviour
Screenshots look the same.
🖼 Screenshots
No response
Expected behaviour
Screenshot should match the player it's called on.
Environment
Static HTML.
Additional info
No response
The text was updated successfully, but these errors were encountered: