Skip to content

chore(assets): jieba 词典 gzip 化 + 删未压缩 models-dev 目录(-7.4MB) - #22

Merged
tall-1997 merged 1 commit into
mainfrom
chore/apk-size-trim
Oct 14, 2026
Merged

tall-1997 merged 1 commit into
mainfrom
chore/apk-size-trim

Conversation

@tall-1997

Copy link
Copy Markdown
Owner

来自 taixu/OmniBot 体积对标(docs/analysis-apk-size-vs-taixu-omnibot.md)的两个零成本瘦身点,功能零损失:

1. 删未压缩 models-dev-api.json(-4.1MB)

代码首选读 gzip 版(416KB),明文版只是 gunzip 失败的回退——本地资产解压失败=APK 损坏,真正的回退是网络刷新路径。删除:

  • 资产本身(4.1MB)
  • ModelsDevApi.kt 的明文回退分支
  • update_models_dev.sh 的明文输出(脚本只产 gzip)
  • 守护测试 BundledModelsCatalogTest 从「双份内容一致」改为「gzip 可解压 + 含已知主力 provider」

2. jieba 词典 gzip 化(5.4MB → 2.1MB,-3.3MB)

  • assets 里 jieba.dict.utf8 / hmm_model.utf8 改为 .gz 形态
  • JiebaEngine 解压落盘时走 GZIPInputStream,落盘文件名不变
  • native 侧(jieba_jni.cpp)读的是落盘名,零改动
  • DICT_VERSION 保持 1:内容未变,已解压的存量 filesDir 副本仍然有效(allPresent 短路,不碰 assets)

验证

  • 本地 gunzip 后字节数与原文件一致(5071207 / 519739,无损)
  • gzip 资产可解压且含 anthropic/openai 键
  • 编译与全量单测交 CI

合计 APK 减约 7.4MB。

…talog

Two zero-cost APK size wins (~7.4MB) found by benchmarking against
taixu / OmniBot (docs/analysis-apk-size-vs-taixu-omnibot.md):

- models-dev-api.json (4.1MB): the app reads the .gzip copy first and
  the plaintext file was only a gunzip-failure fallback — for a local
  asset that means a corrupt APK, and the network refresh is the real
  fallback. Asset, code fallback branch, and the update script's
  plaintext output all removed. The catalog guard test now verifies the
  gzip itself is readable and still carries the known-majority
  providers instead of diffing two copies.
- jieba dictionaries (5.4MB → 2.1MB): jieba.dict.utf8 and hmm_model
  are now gzipped in assets and gunzipped onto filesDir at extract
  time; the native side keeps reading the plain file names, so
  jieba_jni.cpp is untouched. DICT_VERSION stays at 1 — content is
  unchanged and already-extracted copies remain valid.
@tall-1997
tall-1997 merged commit b81580e into main Oct 14, 2026
1 check passed
@tall-1997
tall-1997 deleted the chore/apk-size-trim branch October 14, 2026 12:12
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.

1 participant