Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【思考】如何在内存占用和运行速度中权衡 #1

Closed
LinXueyuanStdio opened this issue Nov 15, 2020 · 1 comment
Closed

Comments

@LinXueyuanStdio
Copy link
Owner

本框架是一个用于字符串动态管理的框架,最常用的场景是按关键字获取字符串,主要的优化目标也是这个场景。

按关键字获取字符串,现有两种方法,稍微分析一下。

  1. 一次性读取当前语言包,把语言包缓存到 static map 中
    1. 运行速度最快,因为字符串在内存里
    2. 内存占用最大,因为整个语言包都加载进内存,很多没有用到,造成内存浪费
  2. 将语言包保持为文件,每次用到的时候再读取到内存,然后使用
    1. 内存占用小,因为只有用到的字符串才加载进内存
    2. 首次运行速度慢,因为第一次加载要频繁从文件读取字符串

我希望综合以上两种方式的优点

  1. 首次运行速度要快,内存可以占用高一点
  2. 后面每次运行速度要尽可能快,内存占用要低

现暂时考虑以下方法

  1. 第一次打开app,一次性读取当前语言包,缓存到 static map中。
  2. 每次使用字符串,给字符串统计使用次数。使用完后,按次数排序,固化到文件,杀死app。
  3. 第二次打开app,读取使用次数最高的 k 个字符串常驻内存,后面有新的字符串再临时从文件读取,返回 2。

因为第一次读取全部语言包到内存,使用时速度最快,内存占用较高,可接受
第二次读取使用次数最高的 k 个字符串到内存。如果用户第二次使用的字符串和第一次相同,那这个就是最优。

@mingmingacc
Copy link

您好,看到有支持RTL的地方,想问下这个在MLang里面需要做什么处理吗

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

No branches or pull requests

2 participants