Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Compression Optimization Plan

  • Explore repository structure and understand current implementation
  • Run existing tests to verify baseline (all 33 tests passing)
  • Update ResourcePacker.cs to implement tiered compression logic
  • Update file format to store compression metadata
  • Update ResourcePackageReader.cs to decompress when reading
  • Add comprehensive tests for compression scenarios (9 new tests)
  • Verify all existing tests still pass (42 total tests passing)
  • Address code review feedback (fix array comparison logic)
  • Run security checks (CodeQL - no alerts)
  • Address PR review comments:
    • Encapsulate tuple as IndexEntry struct
    • Add ResourceDecompressionStream for streaming decompression
  • Update documentation (README.md and blog.md)

Documentation Updates

Added comprehensive documentation about the intelligent compression feature:

README.md

  • Added compression to features list
  • New "Compression" section explaining the tiered strategy
  • Details on compression rules (< 255B, 255B-4KB, > 4KB)
  • Information about automatic format detection
  • Compression benefits and technical details

blog.md (Chinese)

  • Updated core features to include intelligent compression
  • New comprehensive "智能压缩特性" section
  • Detailed compression strategy explanation
  • Compression effectiveness by file type
  • Usage examples and technical details
  • Updated file format documentation
  • Performance considerations for compressed resources

All 42 tests passing. Documentation is comprehensive and accurate.

Original prompt

This section details on the original issue you should resolve

<issue_title>资源打包规则优化建议:分级压缩与采样决策</issue_title>
<issue_description>针对资源打包(.dat 文件),建议采用以下分级压缩与采样决策规则,以提升包体空间利用率和加载性能:

建议规则

  1. 文件小于 255 字节,不压缩。
  2. 文件大于 255 字节且小于 4KB,整文件尝试压缩(如 GZip),若压缩比未达到 5% 则不压缩。
  3. 文件大于 4KB,取前 8KB 作为采样进行压缩评估,若压缩比未达到 5% 则不压缩。
  4. 压缩算法使用 GZip

实现思路

  • 可为已压缩格式(如 jpg、png、zip)直接跳过压缩。
  • 元数据需标记压缩状态、压缩后大小,方便读取与解压。
  • 版本号仍然保持为 1 。

欢迎讨论、完善规则或提出更优实现建议!</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Oct 27, 2025
Copilot AI and others added 2 commits October 27, 2025 03:39
Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copilot AI changed the title [WIP] Update resource packaging rules for compression and sampling Implement tiered compression with GZip for resource packing Oct 27, 2025
Copilot AI requested a review from Soar360 October 27, 2025 03:47
Copilot finished work on behalf of Soar360 October 27, 2025 03:47
Copy link
Contributor

@Soar360 Soar360 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Read index entries (key and length only)
var indexEntries = new List<(string Key, int Length)>();
// Read index entries
var indexEntries = new List<(string Key, int OriginalLength, int StoredLength, bool IsCompressed)>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑封装成 struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed to readonly struct IndexEntry for better type safety and performance. See commit a25f100.

throw new KeyNotFoundException($"Resource with key '{resourceKey}' not found.");

// For compressed resources, we need to decompress first
if (entry.IsCompressed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或许,我们可以创建一个新的类型,类似 ResourceSubStream 那样,而不是直接在内存中进行解压?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Created ResourceDecompressionStream class (similar to ResourceSubStream) that wraps a GZipStream for on-the-fly decompression. This avoids loading entire compressed files into memory. See commit a25f100.

…ession

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copilot finished work on behalf of Soar360 October 27, 2025 04:02
Copilot AI requested a review from Soar360 October 27, 2025 04:02
@Soar360
Copy link
Contributor

Soar360 commented Oct 27, 2025

@copilot 需要更新以下文件:

  • README.md
  • blog.md

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot 需要更新以下文件:

  • README.md
    ...

Documentation updated in commit 446d44d:

README.md:

  • Added compression to features
  • New "Compression" section with tiered strategy details
  • Technical specifications and benefits

blog.md:

  • Updated core features (智能分级压缩)
  • New comprehensive "智能压缩特性" section
  • Detailed compression rules, effects, and usage examples
  • Updated file format and performance sections

Copilot finished work on behalf of Soar360 October 27, 2025 04:58
@Soar360 Soar360 marked this pull request as ready for review October 27, 2025 05:14
@Soar360 Soar360 merged commit 50ae4f0 into main Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

资源打包规则优化建议:分级压缩与采样决策

2 participants