TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Serialization-Based Undo

76 pointsby prideoutover 3 years ago

5 comments

rocquaover 3 years ago
Essentially the idea here is not to muck about with diffs or event &#x2F; command based sourcing.<p>Just store each internal state you might want to recover, in full. Except use compression to store the states you want to recover. In this article, the compression is done based on the &#x27;initial state&#x27;. I imagine there is flexibility on maybe &#x27;checkpointing&#x27; some states once the difference becomes to big. Maybe do the compression not with a prefix of the &#x27;initial&#x27; state but with a prefix of the entire undo history.<p>All this requires is halfway efficient serialization &#x2F; deserialization implementation, and access to Zstandard (I guess other compression algorithms also work).<p>I think the key trick here is that, if you can serialize to bytes, you can just use compression methods as a replacement for storing diffs or other complicated methods for de-duplicating data. This could be a really powerful method to really easily keep a state history without high performance cost. From the developer p.o.v. its like you have each previous state at your fingertips. Whilst in reality the compression ensures it is stored efficiently.
评论 #28906060 未加载
steeleduncanover 3 years ago
It is interesting to compare this to Jonathan Blow&#x27;s talk on the rewind system in Braid [1].<p>This stores complete game states using a compression library to keep memory under control, whereas Braid stored a combination of keyframes, and diffs from those keyframes, to avoid using a compression library.<p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=8dinUbg2h70" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=8dinUbg2h70</a>
Strilancover 3 years ago
This is the design I also usually use for undo&#x2F;redo. Actually for small interactive editors I like to go further and make it so that anytime you do anything the program serializes its state and loads it back in. This is sometimes too costly but has unexpected reliability benefits. It makes sure your serialization code is well exercised, it ensures most of your program states are linkable&#x2F;nameable, and also it&#x27;s sort of like every time you do anything you&#x27;re restarting the program. There&#x27;s much less implicit state that can cause problems. And as a fallback if you do get the program into a bad state you can just hit undo and you&#x27;re back into a good state.
caternover 3 years ago
This is cool, but I don&#x27;t understand the justification for why a more traditional &quot;just store a sequence of events&quot; undo system wasn&#x27;t possible. As the author says in the post on the scripting system, the game scripts access virtual interfaces. Those could just record the methods called before forwarding them on - doesn&#x27;t matter that the scripts make arbitrary method calls. It seems to me that there&#x27;s nothing inherent to &quot;the level script is arbitrary code rather than a list of commands as data&quot; that makes that style of undo impossible.
评论 #28904670 未加载
评论 #28904657 未加载
评论 #28914877 未加载
hosejaover 3 years ago
&gt;but since I’m not a fan of C++ streams, it doesn’t use them internally<p>Nobody does, it&#x27;s one of the worst mistakes of C++.
评论 #28904896 未加载