diff options
| author | Theresa Foley <10618364+tangent-vector@users.noreply.github.com> | 2025-04-16 12:28:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-16 12:28:39 -0700 |
| commit | 2b20e9e150225f8cb75f7be2061f5ec99cbb2f66 (patch) | |
| tree | 1ff5065b73021176f9a0dcb10273c2f372feac28 /source/slang/slang-serialize-container.cpp | |
| parent | 786f456c2558f07c5a396e25ecb635a3c5480313 (diff) | |
Remove support for ad hoc Slang IR compression (#6834)
* Remove support for ad hoc Slang IR compression
This change is part of a larger effort to clean up the approach to
serialization in the Slang compiler. The overall goal is to simplify
and streamline all of the serialization-related logic, so that we are
left with code that is less "clever," and easier to understand for
contributors to the codebase.
Removing support for compression of serialized Slang IR has
benefits that include:
* Reduction in code complexity: consider things like the subtle way
that the `FOURCC`s for compressed chunks were being computed from
the uncompressed versions, and the mental overhead that goes into
understanding that, for anybody who would dare to touch this code.
* Reduction in testing burden: there have been, de facto, two
very different code paths for serialization of the Slang IR, and
it is not clear that the existing test corpus for Slang has
sufficient coverage for both options. By having only a single code
path, every test that performs any amount of IR serialization helps
with test coverage of that one path.
* Opportunity to explore alternatives. This is perhaps a reiteration
of the first point, but once the code is stripped down to the
simplest thing that could possibly work (I am not claiming it has
reached that point yet), it becomes easier for contributors to
understand, and it becomes more tractable for somebody to come along
with an improved approach that performs better (in either
compression ratio or performance) while still being maintainable.
In my own local setup, I found that removing support for Slang IR
compression led to the `slang-core-module-generated.h` file increasing
in size from 46.1MB to 47.4MB. This increase in the `.h` file size
for the core library binary only resulted in a release build of
`slang.dll` increasing from 20.0MB to 20.2MB. Removing the ad hoc
compression support has almost no impact on the size of actual binary
Slang modules *so long* as the additional LZ4 compression step is
being applied to them.
* format code
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-serialize-container.cpp')
| -rw-r--r-- | source/slang/slang-serialize-container.cpp | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/source/slang/slang-serialize-container.cpp b/source/slang/slang-serialize-container.cpp index b5121d373..f82357459 100644 --- a/source/slang/slang-serialize-container.cpp +++ b/source/slang/slang-serialize-container.cpp @@ -290,19 +290,6 @@ namespace Slang RiffContainer::Chunk::Kind::List, SerialBinary::kContainerFourCc); - // Write the header - { - SerialBinary::ContainerHeader containerHeader; - // Save the compression type if used - as can only serialize with a single compression type - containerHeader.compressionType = uint32_t(options.compressionType); - - RiffContainer::ScopeChunk scopeHeader( - container, - RiffContainer::Chunk::Kind::Data, - SerialBinary::kContainerHeaderFourCc); - container->write(&containerHeader, sizeof(containerHeader)); - } - if (data.modules.getCount() && (options.optionFlags & (SerialOptionFlag::IRModule | SerialOptionFlag::ASTModule))) { @@ -356,8 +343,7 @@ namespace Slang sourceLocWriter, options.optionFlags, &serialData)); - SLANG_RETURN_ON_FAIL( - IRSerialWriter::writeContainer(serialData, options.compressionType, container)); + SLANG_RETURN_ON_FAIL(IRSerialWriter::writeContainer(serialData, container)); } // Write the AST information @@ -451,7 +437,7 @@ namespace Slang SerialSourceLocData debugData; sourceLocWriter->write(&debugData); - debugData.writeContainer(options.compressionType, container); + debugData.writeContainer(container); } // Write the container string table @@ -501,18 +487,6 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( return SLANG_FAIL; } - SerialBinary::ContainerHeader* containerHeader = - containerChunk->findContainedData<SerialBinary::ContainerHeader>( - SerialBinary::kContainerHeaderFourCc); - if (!containerHeader) - { - // Didn't find the header - return SLANG_FAIL; - } - - const SerialCompressionType containerCompressionType = - SerialCompressionType(containerHeader->compressionType); - StringSlicePool containerStringPool(StringSlicePool::Style::Default); if (RiffContainer::Data* stringTableData = @@ -532,7 +506,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( { // Read into data SerialSourceLocData sourceLocData; - SLANG_RETURN_ON_FAIL(sourceLocData.readContainer(containerCompressionType, debugChunk)); + SLANG_RETURN_ON_FAIL(sourceLocData.readContainer(debugChunk)); // Turn into DebugReader sourceLocReader = new SerialSourceLocReader; @@ -610,10 +584,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( if (!options.readHeaderOnly) { IRSerialData serialData; - SLANG_RETURN_ON_FAIL(IRSerialReader::readContainer( - irChunk, - containerCompressionType, - &serialData)); + SLANG_RETURN_ON_FAIL(IRSerialReader::readContainer(irChunk, &serialData)); // Read IR back from serialData IRSerialReader reader; @@ -961,8 +932,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( SLANG_RETURN_ON_FAIL( writer.write(module, sourceLocWriter, options.optionFlags, &irData)); } - SLANG_RETURN_ON_FAIL( - IRSerialWriter::writeContainer(irData, options.compressionType, &riffContainer)); + SLANG_RETURN_ON_FAIL(IRSerialWriter::writeContainer(irData, &riffContainer)); // Write the debug info Riff container if (sourceLocWriter) @@ -970,8 +940,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( SerialSourceLocData serialData; sourceLocWriter->write(&serialData); - SLANG_RETURN_ON_FAIL( - serialData.writeContainer(options.compressionType, &riffContainer)); + SLANG_RETURN_ON_FAIL(serialData.writeContainer(&riffContainer)); } SLANG_RETURN_ON_FAIL(RiffUtil::write(&riffContainer, &memoryStream)); @@ -1003,7 +972,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( return SLANG_FAIL; } SerialSourceLocData sourceLocData; - SLANG_RETURN_ON_FAIL(sourceLocData.readContainer(options.compressionType, debugList)); + SLANG_RETURN_ON_FAIL(sourceLocData.readContainer(debugList)); sourceLocReader = new SerialSourceLocReader; SLANG_RETURN_ON_FAIL(sourceLocReader->read(&sourceLocData, &workSourceManager)); @@ -1020,8 +989,7 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( { IRSerialData irReadData; IRSerialReader reader; - SLANG_RETURN_ON_FAIL( - reader.readContainer(irList, options.compressionType, &irReadData)); + SLANG_RETURN_ON_FAIL(reader.readContainer(irList, &irReadData)); // Check the stream read data is the same if (irData != irReadData) |
