Repository navigation
Experiment with compressing individual method contexts - #59000
jakobbotsch wants to merge 2 commits into
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsThis is an experiment to support Brotli compression in method contexts for SPMI collections. Currently the way Brotli is added is pretty unfortunate as I put it in superpmi-shared and then build it in all the superpmi projects that needs I measured some of the characteristics of compression vs no compression. For all the experiments I cleared my file cache between each run using RAMMap (Empty -> Empty Standby List).
The collect command was: py .\src\coreclr\scripts\superpmi.py collect --pmi -assemblies C:\dev\dotnet\runtime\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Root\ -output_mch_path <out_path>Note that the time for collect includes the time for the collection itself, merging/cleaning, building the TOC and doing a test SPMI replay. Also the merging/cleaning steps are quite inefficient because they repeatedly decompress and recompress each method context even when it could just be copied directly from the input to the output. I have not bothered optimizing this but it would probably reduce the time taken for collections significantly. For the replay commands I invoked superpmi.exe directly with a checked JIT. For parallel runs I passed -p. I think the parallel HDD runs are so much faster because the smaller file means the OS keeps it in memory longer. It seems the striding we use with parallel runs is terrible for HDD performance. The PR allows method contexts to individually select compression/no compression so even if we don't want it for the smaller collections, we could potentially use it in case we want to have much larger collections in the future. Are there any comments on whether we want this and what we want for the default (compression or no compression)? And any tips for how to handle the Brotli source files in CMake? cc @dotnet/jit-contrib
|
|
Instead of adding Brotli into the source tree twice, you should move the brotli implementation from |
|
Presumably you could create a static lib out of the brotli files and link them. The JIT does this with the gcinfo lib in src\coreclr\gcinfo, so that might provide a template. |
BruceForstall
left a comment
There was a problem hiding this comment.
This generally looks great.
Some questions about the user experience:
- Should there be options to select the compression mode? The shims don't take command-line arguments, so there would need to be a SUPERPMI_* environment variable to transmit this information.
- There should probably be an
mcscommand to (a) compress a file (using some chosen compression method/level), (b) decompress a file, (c) output the compression statistics. - Do all the commands like "mcs -merge -dedup -thin", "mcs -integ", etc., "just work"?
- Does the TOC ("mcs -toc", use with "superpmi -c NNN") "just work"?
|
|
||
| Assert(buffIndex == totalFileSize); | ||
| return data; |
There was a problem hiding this comment.
Does this do a full copy of the array? If so, that could be expensive.
There was a problem hiding this comment.
No, even if RVO is not used I believe the copy should be elided and a move operation will happen instead.
|
|
||
| WriteFile(hFile, buff2, totalFileSize, &bytesWritten, NULL); | ||
| delete[] buff2; | ||
| static std::vector<unsigned char> applyCompression(const std::vector<unsigned char>&& data, MethodContextCompression compression) |
There was a problem hiding this comment.
Shouldn't this be a MethodContext static (private) member? Same for the decompression function.
|
Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it. |
|
Sorry, I have missed your questions above @BruceForstall.
My hope would be to get this to a place where the overhead of the compression is so negligible that you would never want to turn it off so that something like this would not be necessary (and we would always default to compression on).
Given the above, I was hoping something like this would not be useful. One of my thoughts was that we would support the compression end-to-end so that we never needed to have uncompressed collections/contexts anywhere, to ensure that we could support really big collections without problems.
They worked yes, since the decompression happens before the method contexts are returned. But I believe some of the operations could be optimized to be made faster.
Yes, this part worked too. To be honest I'm not sure that we want a separate TOC file instead of keeping it in the file if we continue to evolve on it. I guess it makes the collection process itself use a little less disk space because there are no TOCs for the intermediate files, but it does complicate other things. My current plans for my next work on this is to use the "chunked" approach we discussed, i.e. where we compress multiple contexts as part of one blob, to get better compression ratio. But this requires changes to how we do parallel SPMI replays/diffs and more, and having to do all of this in C++ (and using PAL) makes it that much harder. Not sure when I'll have time to work on this again, but I'm keeping it in the back of my mind. |
|
One of the original design points of the "MCH" files is that they are simply concatenations of individual method contexts. Changing the file format to include a TOC, and compressing groups of method contexts as one, might break this, although perhaps it would be worth doing so, as well. |
This is an experiment to support Brotli compression in method contexts for SPMI collections.
I picked Brotli because we already have the source in the tree so I believe there are no license considerations.
The main benefit is to reduce the size of collections stored on the disk. I had a hypothesis that for HDDs,
this would also help replay speed because the decompression is faster than reading the full thing. My experiments
seem to indicate that this is true for parallel runs, but I don't think it's for the reason that I expected.
Currently the way Brotli is added is pretty unfortunate as I put it in superpmi-shared and then build it in all the superpmi projects that needs
MethodContext. It would probably be better to build it once and statically link it, but I don't have the necessary cmake knowledge to do that for this experiment. In total, we are building it separately 5 times (6 times if you include System.IO.Compression).I measured some of the characteristics of compression vs no compression. For all the experiments I cleared my file cache between each run using RAMMap (Empty -> Empty Standby List).
The collect command was:
Note that the time for collect includes the time for the collection itself, merging/cleaning, building the TOC and doing a test SPMI replay. Also the merging/cleaning steps are quite inefficient because they repeatedly decompress and recompress each method context even when it could just be copied directly from the input to the output. I have not bothered optimizing this but it would probably reduce the time taken for collections significantly.
For the replay commands I invoked superpmi.exe directly with a checked JIT. For parallel runs I passed -p. I think the parallel HDD runs are so much faster because the smaller file means the OS keeps it in memory longer. It seems the striding we use with parallel runs is terrible for HDD performance.
The PR allows method contexts to individually select compression/no compression so even if we don't want it for the smaller collections, we could potentially use it in case we want to have much larger collections in the future. I also made sure that old collections still load correctly so that transitioning would be smooth.
Are there any comments on whether we want this and what we want for the default (compression or no compression)? And any tips for how to handle the Brotli source files in CMake?
cc @dotnet/jit-contrib