-
Notifications
You must be signed in to change notification settings - Fork 192
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
The time-step elision optimization is broken #681
Comments
Strangely, the current situation is that the constant state compares equal, but |
Might be a missing $! at codeworld/codeworld-api/src/CodeWorld/Driver.hs Line 1174 in 4716ac9
|
Was hoping this might help with #681, but alas, no change.
I admit defeat for now. I added a debug function that printed if any function changed stable names of its result; but adding the debug function in the wrong places makes the problem go away. Perhaps the debugging is preventing a rewrite rule from firing, or something like that? Who knows. But this is some seriously spooky stuff. |
This still doesn't fix the issue, but eliminates a few bugs regarding #681
What is time-step elision ? |
I answered in our email thread, but here's the details for the public record. Suppose I write this code:
In theory, change should be called every frame with a TimePassing event. However, in practice, we can tell that the TimePassing event will be ignored in this case. We can make that observation because The second complication is this: we can't in general compare two states, because they might contain functions or infinite data structures. So instead of comparing with There are two ways to compare for pointer euqality: So what's going on is that we're failing to detect when time-step ellision is possible. Most likely, that means that I've made a mistake with the result that the two state values are equal, but no longer share the same memory location. A common way that happens is that I am applying some modification to a field of a record, and then reconstructing the record with the new value. For example:
Now if I do something like This is almost surely the kind of thing that's going on. But it's a tricky one to track down. I have tried and failed. |
@nixorn A good first step to fixing this is probably to reproduce it in a test. To do that, you'd want to refactor |
Ok, doing. |
|
Looks I need to separate applying of |
I may have been unclear. Here are a few clarifications. First of all, I care about this behaving correctly in GHCJS, not GHC. That's because (a) 99% of users of To make the GHCJS code run in node.js instead of a browser, you'll need to replace a few parts of the behavior. You want to do this at the lowest level possible. A good start would be to write a new instance for
and so on. That won't remove all the browser dependencies, but it will get you started. The remaining browser dependencies can be handled either by moving them to MonadCanvas if it makes sense, or by adding a new |
allows much more code to be shared between the various code paths. My goal here is to help with creating a unit test for #681, which are currently blocked because the driver code is not easily testable. With a bit more progress here, we can stub out the browser-specific canvas bits (or even mock them, using monad-mock) and test the surrounding driver logic.
This doesn't fix the problem, but it does fix the specific causes in the Wrapped type. I don't even really understand why this works. There's some real oddness going on here with strictness. Making all of the non-wrapped fields strict fixes the bug, but it should not be required. I wish things made more sense.
I've noticed high CPU usage (40%+ CPU on a 4-core 2.8 GHz Intel Core i7) in general , even in the trivial program
and even when run under Is this a side-effect of "The time-step elision optimization is broken #681", or a separate problem? (Poking at the Chrome JS console, it appears that what's happening is a busy loop in requestAnimationFrame calling into (I presume) a GCHJS-compiled h$mainLoop function. I'm not sure, because I'm manually pausing/running the JS in Chrome DevTools, which might have bad interactions with real-clock-based timers in CodeWorld runtime) If this is independent of time-step elision, I can file a separate issue if you want to track this. |
Yes, this is the same thing. The system is redrawing the screen at 60fps even though nothing is changing. |
We broke time-step ellision for interactions somewhere. See https://code.world/haskell#PPUTRWUDaX3tF9KMQYGTS-w
The text was updated successfully, but these errors were encountered: