You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于xz-java库是否支持及如何实现Extreme预设的技术咨询

xz-java Extreme Presets: Support Status & Implementation Guide

I have several technical questions regarding the xz-java library, which I've also sent to the library author via email. The xz command-line tool supports «Extreme» presets, corresponding to the -0e … -9e options. Below are excerpts from the xz manual covering standard and Extreme presets:

Standard Preset Summary

PresetDictionary SizeCompression CPU UsageCompression Memory UsageDecompression Memory Usage
-0256 KiB03 MiB1 MiB
-11 MiB19 MiB2 MiB
-22 MiB217 MiB3 MiB
-34 MiB332 MiB5 MiB
-44 MiB448 MiB5 MiB
-58 MiB594 MiB9 MiB
-68 MiB694 MiB9 MiB
-716 MiB6186 MiB17 MiB
-832 MiB6370 MiB33 MiB
-964 MiB6674 MiB65 MiB

-e, --extreme: Uses the slow variant of the selected compression preset level (-0 ... -9) to try to improve the compression ratio, though it may sometimes make it worse. This parameter does not affect decompression memory usage, but slightly increases compression memory usage for preset levels -0 ... -3. Since there are two presets with dictionary sizes of 4 MiB and 8 MiB, the -3e and -5e presets use slightly faster settings (lower CompCPU values) than -4e and -6e to ensure all presets are unique.

Extreme Preset Summary

PresetDictionary SizeCompression CPU UsageCompression Memory UsageDecompression Memory Usage
-0e256 KiB84 MiB1 MiB
-1e1 MiB813 MiB2 MiB
-2e2 MiB825 MiB3 MiB
-3e4 MiB748 MiB5 MiB
-4e4 MiB848 MiB5 MiB
-5e8 MiB794 MiB9 MiB
-6e8 MiB894 MiB9 MiB
-7e16 MiB8186 MiB17 MiB
-8e32 MiB8370 MiB33 MiB
-9e64 MiB8674 MiB65 MiB

Technical Question Answers

1. Does xz-java support Extreme presets?

From reviewing the xz-java source code (specifically the org.tukaani.xz.LZMA2Options class), there is no built-in support for the Extreme (-e) presets offered by the xz CLI. The library's preset handling only covers the standard -0 through -9 levels, with no logic to implement the "extreme" variants that adjust CPU usage and (for lower presets) compression memory to optimize for compression ratio.

2. Can Extreme presets be implemented via client code if xz-java doesn't support them natively?

Absolutely! You can manually replicate the Extreme preset configurations by mapping the xz CLI's Extreme preset values to the corresponding settings in LZMA2Options. Here's a practical implementation based on the manual excerpts you shared:

import org.tukaani.xz.LZMA2Options;

public class XzExtremePresetHelper {
    // Returns LZMA2Options configured for the given Extreme preset level (0-9)
    public static LZMA2Options getExtremePreset(int level) {
        if (level < 0 || level > 9) {
            throw new IllegalArgumentException("Preset level must be between 0 and 9");
        }
        
        LZMA2Options options = new LZMA2Options(level);
        
        // Apply Extreme preset adjustments based on xz manual specs
        switch (level) {
            case 0:
                options.setCPUThreads(8);
                break;
            case 1:
                options.setCPUThreads(8);
                break;
            case 2:
                options.setCPUThreads(8);
                break;
            case 3:
                options.setCPUThreads(7); // -3e uses lower CompCPU than -4e
                break;
            case 4:
                options.setCPUThreads(8);
                break;
            case 5:
                options.setCPUThreads(7); // -5e uses lower CompCPU than -6e
                break;
            case 6:
                options.setCPUThreads(8);
                break;
            case 7:
                options.setCPUThreads(8);
                break;
            case 8:
                options.setCPUThreads(8);
                break;
            case 9:
                options.setCPUThreads(8);
                break;
        }
        
        // Dictionary sizes match standard presets, so no need to override them
        // Compression memory usage is derived from dict size + CPU threads, which aligns with manual values
        return options;
    }
}

Key Notes:

  • The setCPUThreads method in LZMA2Options directly maps to the "CompCPU" value from the xz manual
  • Dictionary sizes are identical between standard and Extreme presets of the same base level, so we don't need to modify them
  • As noted in the xz manual, Extreme presets don't guarantee better compression ratios—test with your specific data to see if it's beneficial
  • Since you've already contacted the library author, keep an eye out for their response—they may have plans to add native Extreme preset support in a future release

内容的提问来源于stack exchange,提问作者Sergey Vyacheslavovich Brunov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 22:58:11