8 ms·
The fastest GIF does not exist
- NotSoVeteran 5y agoAuthor here - loving all the discussion! I was a bit intimidated to submit this to hn - I'm humbled that someone else thought it was worth posting. Of course, happy to answer any questions anyone may have!
- alisonkisk 5y ago
- chrismorgan 5y ago> Interactive Bit > You'll need to enable Javascript to see this section sorry! There's a slider that lets you see how changing the delay in a GIF file will affect the end results. It's pretty cool. Thank you: this is an excellent way of handling the situation.
- NotSoVeteran 5y agoI'm glad someone came across that! Happy you thought it was a good way to handle it
- chrismorgan 5y agoIt’s not very common for people to handle these sorts of situations elegantly. I disable JavaScript by default (mostly for performance, frankly), and I encounter such elegance only once or twice a year. (For myself, I take care on my site in the few places I ever use JavaScript, and also even vary my content in feeds where it depends on JavaScript or site styles, which I’ve never noticed anyone else do. make-and-git-diff-test-harness and dark-theme-implementation are slugs of two sample articles that both vary by JavaScript and feed, I won’t drop links.)
- deleted 5y ago[deleted]
- ronenlh 5y agoGreat writing and research. You added great examples to make it clear, both in code and gifs. It was both fun to read and interesting. I was surprised to see Netscape running, I might try as well to play with the first JavaScript.
- NotSoVeteran 5y agoThank you! I used VirtualBox running Windows 95, but there were a lot of roadblocks - finding a Netscape 2.0 installer, mounting it etc. Unfortunately I didn't document the process at all and have forgotten everything, so I can't give much useful info, apologies. Just know that there is pain down that path.
- skerit 5y agoI thought it was very interesting. I'm also mad right now that we could have had much better looking gifs (and better optimized gifs) for so long!
- miohtama 5y agoI like the ”Internet Explorer 5 is closed source, but could hypothetically look something like this” bit. Is this source code available through MS partnership programs or an old leak?
- ldjb 5y agoI don't believe the source code is still available officially (although it used to be through Microsoft's Shared Source Initiative and Government Security Program), but the Windows 2000 source code was leaked back in 2004. https://news.microsoft.com/2004/02/12/statement-from-microsoft-regarding-illegal-posting-of-windows-2000-source-code/ https://news.microsoft.com/2004/02/12/statement-from-microso...
- draw_down 5y agoWindows 2000 and NT 4 code leaked in 2004.
- est 5y agoI assume IE6 source code (mshtml.dll) was leaked along side with WinXP
- stingraycharles 5y agoI recall there was a leak a long time ago, but definitely well after the IE5-era. Hypothetically, it could be this leak where the code comes from.
- 07d046 5y agoIt's in the Windows 2000 leak.
- rr808 5y agoIts pretty trivial to disassemble binaries back into C++, but its against ToC so you wouldnt admit to doing so.
- nneonneo 5y ago
- Forge36 5y agoThis "in practice spec" is a cool dive into history. There is a similar quirk in the RTF spec where x and y coordinates were swapped.
- ridaj 5y agoThe internet in all its duct tape glory. Prime example of trade-off between cleanliness of implementation and backwards compatibility. As much as I like a pristine, pure spec, the market winners are clear. It pays to keep product debt around.
- keyraycheck 5y agoIf we could only deprecate features more aggressively, our code would be so much cleaner...
- mad182 5y agoSo pretty much the same as this: https://webaim.org/blog/user-agent-string-history/ https://webaim.org/blog/user-agent-string-history/
- btdmaster 5y agoI converted the GIFs to APNG and both ffmpeg and ffplay gave the same results as the browser, so the specification is very consistently ignored.
- xoa 5y agoAn interesting quick dive into how some of the artifacts of historical implementations can carry forward decades later. I'm saving this one. While everyone on HN is probably familiar with a pile of examples of this in our own work particularly if you do anything lower level, this is a nice example because it's really easy to grasp even for total non-programmers and gives a feel for the layers upon layers the digital world is built on. Details on the x86-64 bootstrap sequence are interesting to tech people but this is the sort of thing I might show in a school class. That said at first I thought the author was being a bit tongue in cheek on the suggestion to fix it with: >A downside to making any changes is that the badly formatted GIFs won't render any more. I reckon just be bold, like the release of Netscape 2.0...If Netscape was fine with breaking poorly-made GIFs, we should be too! But we kind of have a bit more content now then when Netscape 2 was released, and it seems they're serious? Support more than 256 colours in a single frame of GIF animation Support fast GIFs (10ms delay) No confusing behaviour with small delay = slow GIF Better compression for GIFs with multiple small areas updated per frame But frankly at this point why? We've got good universally adapted image formats that do more than 256 colors. We've got webm and so on (even Apple caved on that one in the end) for baked animation which is much smaller and more powerful than gif, and plenty of CPU and libraries for generation on the fly. We've got powerful ways to do animation purely with HTML/CSS/SVG/JS. GIF is a historical artifact with a lot of its value at this point purely about old things. This wouldn't even retroactively bring newer capabilities to older systems because it would require updated code which by definition means the ability to run new browsers and thus modern capabilities. I get they really enjoy hacking on gif but come on. Only way I can see it working is if all the players agreed on some metadata that could be added to gifs which wanted 'standards' vs 'historical' playback with the default remaining historical, and potentially also make it a browser setting. That'd still leave the ad issue, but maybe at this point that's moot given the advancements in blockers (and it'd be a very easy thing to look for as an indication of an ad, and thus be selected against).
- layer8 5y ago> We've got webm and so on The spiritual successor to animated GIFs — by that I mean nonlossy pixel-perfect animations — would be APNG, which is supported by virtually all current modern browsers: https://caniuse.com/apng https://caniuse.com/apng
- andrewmcwatters 5y agoIf you think that's crazy, there are other things like this that browser vendors do that are not standardized, and when you start writing a renderer to figure out why your output doesn't match, you find all of these silent agreements everywhere. If you know, you know.
- nayuki 5y agoIf anyone is interested in reading the GIF specification, I reformatted the plain text version into HTML: https://www.nayuki.io/page/gif89a-specification-html https://www.nayuki.io/page/gif89a-specification-html
- andai 5y agoNeat! Is there an automated tool for the conversion? Preferably hooked up to a RFC database?
- nayuki 5y agoI'm not aware of any tools; I converted this document by hand in a few hours. GIF is a popular standard with cultural value, which is why I would do this; I wouldn't do it for any random obscure document. The IETF RFC website has links to HTML and PDF versions, but... For most standards documents, the HTML and PDF versions look just like the plain text version, adding little or no value (e.g. https://www.rfc-editor.org/rfc/rfc1321.txt https://www.rfc-editor.org/rfc/rfc1321.txt ; https://www.rfc-editor.org/rfc/rfc1321.html https://www.rfc-editor.org/rfc/rfc1321.html ; https://www.rfc-editor.org/rfc/pdfrfc/rfc1321.txt.pdf https://www.rfc-editor.org/rfc/pdfrfc/rfc1321.txt.pdf ). The only standard I am aware of with a decently formatted version is DEFLATE ( https://www.rfc-editor.org/rfc/rfc1951.txt https://www.rfc-editor.org/rfc/rfc1951.txt ; https://www.rfc-editor.org/rfc/rfc1951.pdf https://www.rfc-editor.org/rfc/rfc1951.pdf ).
- deleted 5y ago[deleted]
- sbierwagen 5y agoMy favorite piece of GIF trivia is that in the original spec, GIF animations would play once and only once. Netscape used the Application Extension block to add number of loops or loop indefinitely. An Application Extension requires an application identifier. So basically every animated GIF ever made has the string `NETSCAPE2.0` in it. https://en.wikipedia.org/wiki/GIF#Animated_GIF https://en.wikipedia.org/wiki/GIF#Animated_GIF
- kragen 5y ago
- wzdd 5y agoIMO a better, though more complex, solution would be to keep the frame delays as specified in the GIF, but to disable GIF looping if the sum of all frame delays was less than 10 ms. That way you get the one good use case (>256 colour gifs) but malicious or broken GIFs with 0 frame delays don't hang your machine. This is complicated by the fact that browsers (used to?) display the first frame of a GIF before the complete animation was loaded. But you could handle that easily enough by making this decision at the time of first loop rather than at initial GIF load. (Fortunately, this is all largely irrelevant nowadays.)
- secondcoming 5y agoI don't know why the animated gif seems as popular as ever, I can't think of any positives about it... bad colours, large file sizes and are encoders more readily available than proper video encoders? Also, supporting it fully now requires either threading or an event loop. The value isn't worth the complexity.
- h3mb3 5y agoThey usually work where jpg and png images work too, most importantly in most places where you render Markdown. No matter how more efficient a real video file would be, often a short gif right there in the README.md is the perfect way to convey a piece of information.
- LeoPanthera 5y agoIt's still a reasonable format for its original use - images with large areas of solid color where only a small percentage of pixels change across a small number of frames. If your animation has <256 colors then it's even lossless, something not possible with any of the video codecs.
- zamadatix 5y agoH.264, H.265, VP9, and AV1 all support losless encoding (regardless of color count). Webp is the more literal replacement for the GIF use case though and also has no color limitations in the lossless animation mode.
- garaetjjte 5y ago>something not possible with any of the video codecs Which codecs? You can have eg. lossless H264 just fine.
- LeoPanthera 5y agoLossless h264 requires 4:4:4 chroma, which is allowed by the spec but not supported by many consumer playback methods. (QuickTime Player, for example, only supports the yuv420p pixel format.)
- uthmancodex 5y ago[flagged]
- vanderZwan 5y agoGiven that the reason for the forced delay is historical abuse by ads, I'm wondering if back in the days this didn't lead to an arms race between browsers and ads (I wouldn't know because I always use an ad-blocker). For example, after canvas was introduced ads could use those instead.
- wk_end 5y agoWhat's the deal with the "hypothetical" IE5 source code that looks very much like actual IE5 source code?
- garaetjjte 5y agoThere have been leaks over the years.
- OJFord 5y agoI think it's a joke, and the excerpt taken from a leak without admitting that. Along the lines of 'downloading Linux distribution ISOs'.
- joshvm 5y agoRate limiting or clamping "0" delays upwards can also help for polling applications where you want to be as fast as possible, but you're never going to be actually zero. For example if you have a thread that's pulling images from a camera (publishing at 30 fps) in a loop, you can delay for 1ms between polls and nobody is going to know, but that can have an enormous impact on CPU usage; especially on embedded platforms. Instead of running at 100% thread usage (calling camera.read() and waiting for it to return true), the spin/loop cost is basically free and you only need to worry about the cost of acquiring/decoding the frame. In theory branch prediction should help because you'll take the "no image yet" branch 99% of the time, but in practice that just makes the loop iterate faster. I learned this the hard way writing a custom camera publisher in ROS, but I've seen it a lot in tutorial code and I think a lot of beginners make that mistake.
- kajal7052 5y ago
- ufo 5y agoI've got to say that the dancing dog doesn't have the same pizzaz if it's cropped like that, without his friend.
- pilaf 5y agoI really wish that meme would just die. That dog was sick and probably in a lot of pain and it makes me sad every time I see it.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- dahart 5y ago> We follow Firefox's behavior and use a duration of 100 ms for any frames that specify a duration of <= 10 ms. That is interesting & funny. I wonder why there wasn’t just a minimum value. This article doesn’t talk about what happens after the delay is triggered, or that a value of 10ms won’t work for the average browser, video hardware & monitor. That’d be a refresh rate of 100 frames per second, and a lot of monitors are 60Hz refresh. Don’t browsers default to 60Hz refresh as well? (MDN docs mention requestAnimationFrame callbacks are usually 60/sec, or 16.7ms apart, for example.) This means with a timeout of 20ms, you’ll probably get a janky animation where one frame gets doubled every 6 frames. I guess with GIF it’s not possible to solve that since the spec doesn’t allow you to match typical refresh rates.
- lewispollard 5y agoYeah, as a gamedev I was surprised not to see this in the article. There's often a default assumption in renderers that "60 fps" is the baseline (and most typical devices will be limited to that). Obviously gaming devices and newer smartphones push above that to 120, 144 or 240 fps. But in gamedev you're always faced with this problem of update frequency of anything that will be displayed to the player; if you update too fast (or too slow), you're gonna get "stutters" and skipped (or stuck) frames as the state updates faster than the renderer can render it (when too fast), or at a rate that's out of sync with the actual frames being pushed to the monitor (too slow, at a rate that's not evenly divisible by the frame rate).
- bradknowles 5y agoThere is no GIF faster than "no GIF". So, of course it doesn't exist!
- YaBomm 5y ago
- tyingq 5y agoI checked ImageMagick, and was somewhat surprised they don't note this at all. On this page, for example: https://legacy.imagemagick.org/Usage/anim_basics/ https://legacy.imagemagick.org/Usage/anim_basics/ , scroll down to "-delay", and it just says "Set the time delay (in 1/100th of a second)..."