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

没有指定字体时绘制文字超级耗时 #3

Open
Misaka-Mikoto-Tech opened this issue Jun 4, 2023 · 2 comments
Open

没有指定字体时绘制文字超级耗时 #3

Misaka-Mikoto-Tech opened this issue Jun 4, 2023 · 2 comments

Comments

@Misaka-Mikoto-Tech
Copy link

https://github.com/lgc-NB2Dev/nonebot-plugin-multincm
我在使用这个点歌插件时发现在docker上绘制歌曲列表耗时10s,绘制歌词耗时至少30s,使用 viztrace 进行性能分析后发现最大的耗时在 pil_utils 在绘制文字函数内,具体的说是 Text2Image.from_bbcode_text() 函数里调用的 get_proper_font(),我认为可以创建一个 Dict, 缓存所有的 Font 对象,这样可能会多占用一些内存,但是不会出现频繁切换 Font 耗时巨大的问题了

@MeetWq
Copy link
Owner

MeetWq commented Jun 4, 2023

耗时主要是需要对每个字符逐一判断字体中是否包含该字符,为了实现字体的 fallback
同时每个字符逐一绘制也比整段绘制耗时
可以指定字体并设置 font_fallback=False,可以减少字体fallback的耗时

总的来说这个用来绘制大段文字的时候很拉(
未来可能会使用别的库绘制文字来提升性能 #2

@Misaka-Mikoto-Tech
Copy link
Author

这么设置后绘制时间并没有明显的提升,感觉还是其它地方有问题

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