News for hackers. Stuff that matters.

peterwaller-arm

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @03:57PM (#29282369)
Author here. This is correct, we set out to do binary diffing but we soon discovered that if you put similar enough object files together in a stream, and then compress the stream, zstandard does a fantastic job at compressing and decompressing quickly with a high compression ratio. The existing binary diffing tools can produce small patches, but they are relatively expensive both to compute the delta and to apply the patches.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @12:34PM (#29279849)
Yes, this is less great than I would like! :( :)
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @12:15PM (#29279586)
Author here, I'd like to see such a comparison too actually, but I'm not in the position to do the work at the moment. We did some preliminary experiments at the beginning, but a lot changed over the course of the project and I don't know how well elfshaker fares ultimately against all the options out there. Some basic tests against git found that git is quite a bit slower (10s vs 100ms) during 'git add' and git checkout. Maybe that can be fixed with some tuning or finding appropriate options.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @12:09PM (#29279497)
Yes you could do that. On the other hand, all revisions for a month is 100MiB, and all revisions we've built spanning 2019-now are a total of 2.8GiB, so we opted to forego implementing any object negotiation and just say 'you have to download the 100MiB for the month to access it'. I think you could a push/pull protocol could be implemented, but at that point probably git might do a reasonable job in that case :)
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @12:05PM (#29279442)
Nice, I bet dwarfs would do well at our use case too. Thanks for sharing.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @11:01AM (#29278521)
ThinLTO can be pretty quick if you have enough cores, it might work. Not sure how well the LTO objects compress against each other when you have small changes to them. It might work reasonably.

manyclangs is optimized to provide you with a binary quickly. The binary is not necessarily itself optimized to be fast, because it's expected that a developer might want to access any version of it for the purposes of testing whether some input manifests a bug or has a particular codegen output. In that scenario, it's likely that the developer is able to reduce the size of the input such that the speed of the compiler itself is not terribly significant in the overall runtime. Therefore, I don't see LTO for manyclangs as such a significant win. But it is still hoped that the overall end-to-end runtime is good, and the binaries are optimized, just not with LTO.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @10:51AM (#29278395)
> maybe mention this as well in the README?

We've tweaked the readme, I hope it's clearer.

It would be great to provide this for gcc too. The project is new and we've just started out. I know less about gcc's build system and how hard it will be to apply these techniques there. It seems as though it should be possible though and I'd love to see it happen.

To infer the object->executable dependencies we currently read the compilation database and produce a stand-alone link.sh shell script, which gets packaged into each manyclangs snapshot.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @10:19AM (#29278038)
(Copying from Q&A) Before starting out some time ago, I did some experiments with bup. I had a good experience with bup and high expectations for it. However, I found that quite a lot of performance was left on the table, so I was motivated to start elfshaker. Unfortunately that time has past so I don't have scientific numbers for you measured with other software at this time.

As an idea of how elfshaker performs, we see ~300ms time to create a snapshot for clang, and ~seconds-to-minute to create a binary pack containing thousands of revisions. Extraction takes less than a second. One difference of elfshaker compared with some other software I tested is that we do the compression and decompression in parallel, which can make a very big difference on today's many-core machines.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @10:18AM (#29278024)
<3
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @10:12AM (#29277958)
We've just added an applicability section, which explains a bit more what we do. We don't have any ELF specific heuristics [0].

https://github.com/elfshaker/elfshaker#applicability

In summary, for manyclangs, we compile with -ffunction-sections and -fdata-sections, and store the resulting object files. These are fairly robust to insertions and deletions, since the addresses are section relative, so the damage of any addresses changing is contained within the sections. A somewhat surprising thing is that this works well enough when building many revisions of clang/llvm -- as you go from commit to commit, many commits have bit identical object files, even though the build system often wants to rebuild them because some input has changed.

elfshaker packs use a heuristic of sorting all unique objects by size, before concatenating them and storing them with zstandard. This gives us an amortized cost-per-commit of something like 40kiB after compression with zstandard.

[0] (edit: despite the playful name suggesting otherwise -- when we chose the name we planned to do more with ELF files, but it turned out to be unnecessary for our use case)

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @10:01AM (#29277844)
Author here. Compressed data is unlikely to work well in general, unless it never changes.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:55AM (#29277779)
Author here. No architecture specific processing currently. Most of the magic happens in zstandard (hat tip to this amazing project).

Please see our new applicability section which explains the result in a bit more detail:

https://github.com/elfshaker/elfshaker/blob/1bedd4eacd3ddd83...

In manyclangs (which uses elfshaker for storage) we arrange that the object code has stable addresses when you do insertions/deletions, which means you don't need such a filter. But today I learned about such filters, so thanks for sharing your question!

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:53AM (#29277760)
Done, hopefully this is clearer. Please let us know if you see a way to improve it further: https://github.com/elfshaker/elfshaker/pull/60
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:42AM (#29277645)
(Disclosure: I work for Arm, opinions are my own)

Author here. elfshaker itself does not have a dependency on any architecture to our knowledge. We support the architectures we have use of. Contributions to add missing support are welcome.

manyclangs provides binary pack files for aarch64 because that's what we have immediate use of. If elfshaker and manyclangs proves useful to people, I would love to see resource invested to make it more widely useful.

You can still run the manyclangs binaries on other architectures using qemu [0], with some performance cost, which may be tolerable depending on your use case.

[0] https://github.com/elfshaker/manyclangs/tree/main/docker-qem...

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:37AM (#29277587)
Author here. The executables shipped in manyclangs are release builds! The catch is that manyclangs stores object files pre-link. Executables are materialized by relinking after they are extracted with elfshaker.

The stored object files are compiled with -ffunction-sections and -fdata-sections, which ensures that insertions/deletions to the object file only have a local effect (they don't cause relative addresses to change across the whole binary).

As you observe, anything which causes significant non-local changes in the data you store is going to have a negative effect when it comes to compression ratio. This is why we don't store the original executables directly.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:32AM (#29277547)
Author here. I've used bup, and elfshaker was partially inspired by it! It's great. However, during initial experiments on this project I found bup to be slow, taking quite a long time to snapshot and extract. I think this could in principle be fixed in bup one day, perhaps.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:17AM (#29277347)
Author here, I agree with xdfgh1112, please take care before using brand new software to store your backups!
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:16AM (#29277336)
Author here, this software is young, please don't use it for backups!

But also, in general, it might not work well for your use case, and our use case is niche. Please give it a try before making assumptions about any suitability for use.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:13AM (#29277305)
Performing poorly with non-textual data happens for a a number of reasons. Binary data, when changed, often have a lot of 'non-local' changes in them. For example, a PSD file might well have a compression algorithm already applied to it. An insertion/deletion is going to result in a very different compressed representation for which there is no good way to have an efficient delta. elfshaker will suffer the same problem here.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:07AM (#29277230)
Author here, I don't think it would apply well to that scenario. elfshaker is good for manyclangs where we ship 2,000 revisions in one file (pack), so the cost of individual revision is amortized. If one build of llvm+clang costs you some ~400 MiB; a single elfshaker pack containing 2,000 builds has an amortized cost of around 40kiB/build. But this amazing win is only happening because you are shipping 2,000 builds at once. If you wanted to ship a single delta, you can't compress against all the other builds.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @09:00AM (#29277156)
Author here, it works particularly well for our presented use case because it has these properties:

* There are many files,

* Most of them don't change very often,

* When they do change, the deltas of the binaries are not huge.

So, if the image files aren't changing very much, then it might work well for you. If the images are changing, their binary deltas would be quite large, so you'd get a compression ratio somewhat equivalent to if you'd concatenated the two revisions of the file and compressed them using ZStandard.

Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:57AM (#29277134)
Author here, I don't currently know how this compares to git-lfs. It it is possible git-lfs would perform quite well on the same inputs as elfshaker works on. If git-lfs does already work well for your use case I'd recommend using that rather than elfshaker, as it is more established.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:56AM (#29277124)
Author here. I'm unsure whether this would apply very well to cargo or not. If it has lots of pre-link object files, then maybe.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:55AM (#29277116)
Author here. Maybe, it's a fun idea. I have toyed with providing a fuse filesystem for access to a pack but my time for completing this is limited at the moment.
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:55AM (#29277113)
Author here. We'd love this to be a thing, but this is young software, so we don't recommend relying on this as a single way of doing a backup for now. Bear in mind that our main use case is for things that you can reproduce in principle (builds of a commit history, see manyclangs).
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:52AM (#29277084)
One of the authors here, thanks for the feedback. We've tried to improve it here: https://github.com/elfshaker/elfshaker/pull/59
Re:Elfshaker: Version control system fine-tuned for binaries on Friday November 19, 2021 @08:41AM (#29277003)
An author here, I agree! The packfile format is heavily inspired by git, and git may also do quite well at this.

We did some preliminary experiments with git a while back but found we were able to do the packing and extraction much faster and smaller than git was able to manage. However, we haven't had the time to repeat the experiments with our latest knowledge and the latest version of git. So it is entirely possible that git might be an even better answer here in the end. We just haven't done the best experiments yet. It's something to bear in mind. If someone wants, they could measure this fairly easily by unpacking our snapshots and storing them into git.

On our machines, forming a snapshot of one llvm+clang build takes hundreds of milliseconds. Forming a packfile for 2,000 clang builds with elfshaker can take seconds during the pack phase with a 'low' compression level (a minute or two for the best compression level, which gets it down to the ~50-100MiB/mo range), and extracting takes less than a second. Initial experiments with git showed it was going to be much slower.