Skip to content

Time Travel Debugging#2910

Merged
hecrj merged 11 commits intomasterfrom
feature/time-travel
Apr 29, 2025
Merged

Time Travel Debugging#2910
hecrj merged 11 commits intomasterfrom
feature/time-travel

Conversation

@hecrj
Copy link
Member

@hecrj hecrj commented Apr 29, 2025

Introducing Comet

I never properly introduced comet, so please let me.

comet is a new companion debugging tool that can be summoned by pressing F12 when the debug feature is enabled—replacing the old (and hideous) debug overlay.

comet_1080.mp4

When the debug feature is enabled, an iced application will send performance metrics through a socket to any server implementing the iced_beacon protocol.

comet is one of such servers. It is built with iced itself and you can find the code over here: https://github.com/iced-rs/comet

Of course, this all means you could build your own custom debugger if you wanted to! It should all be reusable enough.

Custom Performance Metrics

As I introduced in #2891, you can decorate any piece of code with debug::time and debug::time_with to time and visualize different parts of your app.

comet-custom_timings-720p.mp4

Time Traveling

As you know, iced uses the Elm Architecture. One of the advantages of this architecture is that application state can only be mutated in a single place: update—and only in response of a Message. Furthermore, impure side effects are encouraged to happen inside Task and Subscription which are run indirectly by the runtime.

Effectively, this means that if we have an initial state and a list of messages, then we should be able to replicate any state the application has been at any point in time. In other words, we can time travel.

comet-time_travel.mp4
comet-time_travel-02.mp4
comet-time_travel-03.mp4

Pretty cool, huh? Time traveling can be enabled with the new time-travel feature. Activating it will force a Clone bound on your Message type.

It goes without saying but... the feature is very experimental! It will only work well if your update logic is pure; meaning it does not rely on external state (e.g. calling Instant::now).

Use it carefully, it may eat your laundry!

@hecrj hecrj added this to the 0.14 milestone Apr 29, 2025
@hecrj hecrj merged commit 8ba993a into master Apr 29, 2025
30 checks passed
@hecrj hecrj deleted the feature/time-travel branch April 29, 2025 19:53
@Tahinli
Copy link
Contributor

Tahinli commented Apr 30, 2025

This update is more than awesome. Thanks a lot!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments