6 ms·
How Photoshop solved working with files larger than can fit into memory
- interroboink 3y agoIt's a bit of a roundabout article, given that it's ostensibly talking about the Web version of Photoshop. Basically, Adobe already solved the problem (for decades, now) with a traditional non-web application by using the filesystem. And the new bit here is that Chrome offers a filesystem for web apps to use [1], so from the web app's point of view, it can still use the same essential solution that the native app would. It doesn't really go into the guts of how PS actually manages all that data in much detail. Just "it goes to the filesystem in a smart way." [1] The "origin private file system": https://developer.chrome.com/articles/file-system-access/#accessing-the-origin-private-file-system https://developer.chrome.com/articles/file-system-access/#ac...
- PaulHoule 3y ago... application-based virtual memory has been a thing since CICS on mainframes back in the 1970s.
- astrange 3y agoPhotoshop can't rely on mmap, because its scratch file implementation is older than most modern OSes, and some systems have virtual memory limits it exceeds, not just physical memory limits. Though I'm not sure the browser even has mmap capability.
- kevingadd 3y agoIt's unfortunate that there's still no mmap equivalent for I/O in the browser, so you can't do demand paging or anything like that. Nothing approaching zero-copy either, you're typically looking at two copies or more. At least the OS page cache will probably help you out.
- NikkiA 3y agoScratch files, now that's a memory I'd repressed.
- accrual 3y agoMake sure you keep your scratch files on a separate disk for extra performance! 8)
- NikkiA 3y agoI remember someone I knew that insisted on using a ram disk as his scratch disk... Like, uh.... ok, you do that, good luck.
- mjevans 3y agoIf the app was from an era where RAM was much smaller, but now there's enough RAM for the use case, this makes sense.
- eternityforest 3y agoLinux is full of stuff that writes to disk all the time. Browsers do it too. It's possible to do multiple GB an hour doing nothing on some versions with extensions, just from writing and rewriting the same file every minute for probably no good reason other than a dev hated complexity too much to check for unnecessary writes and not wear out the SSD.
- pajko 3y agoThere was a time when the OS could not use the whole RAM directly the hardware had, and it was a use case to put a ram disk or a swap file there.
- NikkiA 3y agoIf the OS can't see the RAM, then the OS provided ramdisk can't use it either. But in this case, the use-case for using a ramdisk for a PS scratch disk came from using an A23-aware patched version of System 5.x/6.x with a version of Photoshop that was not A23 aware. AFAIK This was a VERY tiny window around PS1.0 and possibly PS2.0, by the time of PowerPC and System 7.5+ (which this user had), there was very definitely absolutely no advantage to partitioning the RAM away from programs. At a guess, someone had told them to do it this way in the era of the early Mac IIs and such, but they hadn't grasped the 'why'
- psychphysic 3y agoThey used coding and filesystems so the webpages didn't crash.
- Cthulhu_ 3y agoThey created a GUI using Visual Basic to track the killer's IP
- jdmoreira 3y agoPhotoshop discovered mmap?
- wongarsu 3y agoExcept when exporting files, where it still has weird size restrictions (somewhere around 10k pixels per side)
- cubefox 3y agoThat's ironic, given that it's a Chrome blog post. Because recently someone here said that Google / the Chrome team used their market power to kill JPEG XL (a proposed jpeg successor) in favor of AVIF, which has weird size restrictions.
- jsheard 3y agoThis is about the web version of Photoshop, there is no mmap there.
- mike_hock 3y agoNo, we've (collectively) discovered that we have a lot of mature technologies (like mmap), mature platforms and extremely fast hardware, so we created a crippled software development platform on a bloated layout engine so people can get creative again hacking around the arbitrary constraints and design flaws of the platform to solve problems that had been solved 40 years ago.
- ElFitz 3y agoWeb browser did drastically simplify delivery and deliverability though. Not that there wouldn’t have been alternatives had web apps not become a thing. It’s just more user-friendly than most current open alternatives (eg apt-get), and more open than most current user-friendly alternatives (eg app stores).
- vlovich123 3y agoWhy doesn’t WASM offer a 64-bit mode?
- jsheard 3y agoIt's in the works: https://github.com/WebAssembly/memory64 https://github.com/WebAssembly/memory64 Starting with 32bit had some performance advantages because 64bit runtimes can use virtual memory shenanigans to implement bounds checking with zero overhead. In wasm64 they'll have to do explicit bounds checking instead.
- jcparkyn 3y ago>... 64bit runtimes can use... Did you mean 32bit?
- jsheard 3y agoNo, I mean running 32bit wasm code on a 64bit runtime. The trick is that a 32bit wasm instance can only address up to 4GB of memory, and 64bit hosts give you terabytes of address space to play with, so you can reserve all 4GB of address space up front and incrementally commit the pages as the wasm memory grows. If the wasm code tries to access a page beyond what's been committed it will trigger a hardware exception, so there's no need to perform explicit bounds checking. This only works because the wasm address space is significantly smaller than the hosts address space.
- vlovich123 3y agoYou could do the same with 64-bit by choosing somewhere south of 48-bits of actual address space that you hand out, no?
- jsheard 3y agoThat's one way they could do it, not quite free since they'd have to mask off the high address bits at each load/store, but that's probably cheaper than adding a full branch at every load/store. I think the wasm spec would have to be amended for that to be legal though, currently out-of-bounds memory accesses must throw an exception one way or another, and silently dropping the high bits of addresses may turn an out-of-bounds access into an in-bounds access that doesn't throw.
- keville 3y agoPhotoshop wasn't the one to solve this, as others have mentioned. Adobe likely owns the xRes intellectual property, though: https://en.wikipedia.org/wiki/Macromedia_xRes https://en.wikipedia.org/wiki/Macromedia_xRes
- resoluteteeth 3y ago> Photoshop wasn't the one to solve this, as others have mentioned. > Adobe likely owns the xRes intellectual property, though: Photoshop has used scratch files and it's own virtual memory system since long before adobe bought macromedia
- jval43 3y agoNow do iOS. Content-aware fill still fails with OOM on iPad Pro, yet works fine on older Macs with less processing power.
- MontagFTB 3y agoiOS VM system doesn’t use the disk for paging, so it’s quite a different beast than a machine with TB of available space.
- deleted 3y ago[deleted]
- tabtab 3y agoFile buffering RAM and/or arrays was invented long before Adobe. The tricky part is probably optimizing the image processing algorithms to fit the filing method(s). For example, if images are split into "tile files", and a given algorithm requires referencing too many files/tiles at a time, creating too much file I/O, then it probably needs to be reworked into a tile-friendly algorithm.
- OnlyMortal 3y agoIf I recall correctly, TIFF has the ability to tile an image.
- deleted 3y ago[deleted]
- evmar 3y agoI worked on some memory stuff for Figma, a similar app, though it's surely changed since I did. One interesting thing about Photoshop's perspective is that it's fundamentally about "files", which is like a single bytestream that contains all the picture and which must be transferred to the browser to work on. A Figma document also can refer to images, but in a different way. The sum of the document data (like layout) and the image pixels can be extremely large, like gigabytes, but you can transfer those two things separately from server to client.
- chakintosh 3y agoMight be off-topic but always wondered why Figma limits files to 2Gb, even the paid users. I remember once I had to present my work to stakeholders of a large company and when I opened Figma I was met with the dreaded red banner saying I exceeded the 2Gb limit and wouldn't open the file even for viewing. I was frantically posting on the forums and emailing customer support for a solution. Luckily they replied quickly and suggested I create a new file and paste the important bits on it and leave out the old stuff.
- evmar 3y agoIt was a memory limit imposed by the browser.
- throwawayai2 3y agoNow if only Figma could catch up to Adobe...
- aleph_minus_one 3y agoIt perhaps will soon: - https://www.cnbc.com/2022/09/15/adobe-to-acquire-design-platform-figma-for-20-billion.html https://www.cnbc.com/2022/09/15/adobe-to-acquire-design-plat... - https://www.theverge.com/2022/9/15/23354532/adobe-figma-acquisition-20-billion-official https://www.theverge.com/2022/9/15/23354532/adobe-figma-acqu...
- ChrisMarshallNY 3y agoWe were doing that, with the software (scanner drivers and image processing -BIG files) my team wrote, decades ago. It's very similar to VM. We paged and indexed everything.
- mannyv 3y agoI thought this was pretty well-known. Adobe has been running their own VM engine for a long time now. I'm not sure which Photoshop first shipped with it, but given how pretty much everyone in prepress used it it's likely since at least Photoshop 3.
- jasomill 3y agoVersion 1, actually[1]: The PS.temp file is a special file created by the Adobe Photoshop program to implement the program's virtual memory scheme. Virtual memory allows you to work on images of nearly any size, by using a hard disk instead of RAM (random-access memory) to hold information. The PS.temp file contains the program's virtual memory information. The file is normally deleted when you quit the program. For implementation details, see the files UVMemory.p and UVMemory.inc1.p in the source distribution[2]. [1] https://archive.computerhistory.org/resources/access/text/2013/01/102640940-05-01-acc.pdf#page=410 https://archive.computerhistory.org/resources/access/text/20... [2] https://computerhistory.org/blog/adobe-photoshop-source-code/ https://computerhistory.org/blog/adobe-photoshop-source-code...
- villgax 3y agoPandas has to deal with the same crap, thankfully Dask & other out of core packages fix the issues
- awinter-py 3y agosome sort of spinning metal thing with platters and read heads and magnets and stuff?
- deleted 3y ago[deleted]
- myshpa 3y agoA free photoshop alternative, one man show https://www.photopea.com/ https://www.photopea.com/
- goolz 3y agoYes! I am a daily user plus the dev seems like a great guy(he did an awesome AMA back in the day). One of the few places I make it a point to whitelist my ad blocker. So glad to see this shout out.
- londons_explore 3y agoI think it's a shame the application has to implement this at all. The application should be giving hints, and then the OS deciding what to load and when.
- abujazar 3y agoThis is kinda funny. I worked on 400 MB+ files in Photoshop on a Mac with 128 MB memory in 1999.
- dhosek 3y agoDonald Knuth used a pre-release version of Photoshop (at Adobe headquarters after the employees had gone home for the day) to process the images for his book 3:16. He was using multiple Macs to parallelize his process, and there were frequent crashes. This was back in the days of Macs with 512K of RAM which makes your 128MB Mac seem positively capacious by comparison.
- icehawk 3y agoHe stated that would have been in the summer of 1989-- so Macs actually could have had anywhere from 1-128MB. 128MB would be unlikely, but the SE/30 was released in January of the same year.
- Dalewyn 3y agoFor the newer people clearly unaware, this is known as a "scratch disk"[1][2]. Now git off mah lawn ya greenhorns. :V [1]: https://helpx.adobe.com/photoshop/using/scratch-disks-preferences.html https://helpx.adobe.com/photoshop/using/scratch-disks-prefer... [2]: https://en.wikipedia.org/wiki/Scratch_space https://en.wikipedia.org/wiki/Scratch_space
- fractallyte 3y agoSatori Paint (https://www.satoripaint.com/ https://www.satoripaint.com/) achieved the same result (working with too-large files for available RAM) in the late 1990s. Hugely innovative, vector-based painting that looked like bitmap painting! But it was resolution independent (https://www.satoripaint.com/Tutorials/Workingwithverylargeimages.html https://www.satoripaint.com/Tutorials/Workingwithverylargeim...). Here's a gallery (sadly, thumbnails only): https://web.archive.org/web/20070813084252/http://www.animation-backgrounds.com/soft/software1.html https://web.archive.org/web/20070813084252/http://www.animat... And the original of this page showed how it was possible to zoom into an apparent bitmap image to an incredible degree (demonstrating the vector resolution-independence of Satori): https://web.archive.org/web/20070804225012/http://www.animation-backgrounds.com/articles/artic01/art01p1.html https://web.archive.org/web/20070804225012/http://www.animat... [As far as I recall, it zoomed into the writing on the clipboard on the right, to show a single period!] Incredible software!
- resoluteteeth 3y ago> Satori Paint (https://www.satoripaint.com/ https://www.satoripaint.com/) achieved the same result (working with too-large files for available RAM) in the late 1990s. Desktop photoshop also had the ability to work with files too large for ram in the 90s
- hamburglar 3y agoThis isn't even Adobe's first attempt at solving this problem. Old, old versions of Photoshop in the early 90's (I believe it was introduced in Photoshop 2.5) had an ancient hack called "quick edit" which would allow you to select a file and then open a "slice" of the file, which is a specified bounding box within the file (and not only x,y coordinates -- it could also select a subset of the color channels). It would then present that chunk of the file as its own standalone document window which you could manipulate to your heart's content, then when you saved it, it wrote the slice back out to the original document. It only supported a subset of graphics formats because each one had to have custom code to read and write the slice data.
- ec109685 3y agoI wonder what the intersection of people who do not know what RAM and Virtual Memory are, but interested in this article? “ The amount of memory also varies from device to device, as you know when you order a new computer or device and specify the amount of Random-Access Memory (RAM) desired. Many of these platforms also support virtual memory, which allows an application to use more memory than is physically available.”
- benjifri 3y agoSEO...