# Xiaoyifang/goldendict 加载图片词典比较慢，不知能否优化？

**URL:** <https://forum.freemdict.com/t/topic/23713>\
**Category:** 软件经验交流展望\
**Tags:** goldendict\
**Created:** [2023 年9 月 29 日 11:52 UTC](https://forum.freemdict.com/t/topic/23713 "2023-09-29T11:52:15Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 04:04 UTC](https://forum.freemdict.com/t/topic/23713/21 "2023-10-01T04:04:47Z")

</div>

GoldenDict-NG 使用的现代浏览器，支持的 CSS3 样式更多，会更美观，但受词典质量的影响很大。GoldenDict 官方原版和 MDict 因为浏览器比较古老，在加载网页时遇到 CSS3 样式很多就直接忽略了，所以渲染会更快。

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 07:38 UTC](https://forum.freemdict.com/t/topic/23713/22 "2023-10-01T07:38:20Z")

</div>

比如这个现代汉语规范词典，查询或翻页大概需要1、2秒一次，不清楚为什么慢，应该不是css和html的问题吧

链接: [https://pan.baidu.com/s/1Dy9CWKxhAI\_RroM89HwnXA](https://pan.baidu.com/s/1Dy9CWKxhAI_RroM89HwnXA) 提取码: arc3 复制这段内容后打开百度网盘手机App，操作更方便哦  
–来自百度网盘超级会员v4的分享

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 10:46 UTC](https://forum.freemdict.com/t/topic/23713/23 "2023-10-01T10:46:39Z")

</div>

翻了大概 100 页，首次加载或者翻页每次都在 400ms 以内完成，首次加载图片用时 180-250ms，第二次加载相同图片是 40-50ms，没有到 1-2 秒的情况。

深色模式下时间会拉长到 700-800ms 完成。是不是开了深色模式？

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 11:39 UTC](https://forum.freemdict.com/t/topic/23713/24 "2023-10-01T11:39:41Z")

</div>

没开启深色模式，就正常白色，很奇怪 xiaoyifang 版在我电脑上就是很慢（我电脑不垃圾，i7-12标压）

![GoldenDict_gxprGzfe0O](https://forumcdn.freemdict.com/uploads/default/original/3X/3/f/3f02d8a23c6108d1687d78edd29a97559329f87c.gif)

Goldendict-ng 23.07.25-alpha.20230730.f7e43479  
Qt 5.15.2 Visual C++ Compiler 192930151 windows winnt 10.0.22621 x86\_64-little\_endian-llp64  
Flags:USE\_XAPIAN MAKE\_ZIM\_SUPPORT USE\_ICONV MAKE\_CHINESE\_CONVERSION\_SUPPORT

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年10 月 1 日 11:42 UTC](https://forum.freemdict.com/t/topic/23713/25 "2023-10-01T11:42:42Z")

</div>

我的情况跟你这一模一样，能明显感受到图片是逐渐显示出来的。

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 12:19 UTC](https://forum.freemdict.com/t/topic/23713/26 "2023-10-01T12:19:59Z")

</div>

我认为是浏览器的差异，大图加载慢。我把 goldendict 内置的静态资源请求，全部屏蔽了，只保留词典的资源请求，测试对结果影响不大，整个加载时间只减少了 80-100ms，从400ms下降到了300ms。

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 12:25 UTC](https://forum.freemdict.com/t/topic/23713/27 "2023-10-01T12:25:29Z")

</div>

浏览器的差异啥意思，是跟Win系统当前默认浏览器有关吗。还有就是如何屏蔽，也想试试看，大佬能指点下吗

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 12:42 UTC](https://forum.freemdict.com/t/topic/23713/28 "2023-10-01T12:42:38Z")

</div>

和系统没关系，GD 官方原版用的浏览器是 QtWebkit，xiaoyifang 的版本用的浏览器是 QtWebEngine，前者比较古老，大概相当于2012年的浏览器，而后者是现代浏览器，封装的 Chromium。

你先打开一个词条，然后在GD的网页里，右键审查元素，切换到 Network 面板，勾选 Disable cache。  
然后点击GD的历史面板的词条，可以随意切换词条，此时Network面板，会显示加载的资源文件。在资源名称上右键，选择 Block request URL，即可屏蔽资源。再切换一次词条，可以看到资源屏蔽成功。

 ![截屏2023-10-01 20.39.58](https://forumcdn.freemdict.com/uploads/default/original/3X/3/2/32a92b2b00775d9f90759dc4be2391493b083f6b.png)

 ![截屏2023-10-01 20.45.08](https://forumcdn.freemdict.com/uploads/default/original/3X/6/5/6588068a045dca5ef2af5e5457f5b5719808d70c.png)

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 12:51 UTC](https://forum.freemdict.com/t/topic/23713/29 "2023-10-01T12:51:22Z")

</div>

加载图片很慢

 ![image](https://forumcdn.freemdict.com/uploads/default/original/3X/8/4/842cf8bf1699c1bedba26ffb36dcb93299e6d547.png)

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 12:57 UTC](https://forum.freemdict.com/t/topic/23713/30 "2023-10-01T12:57:53Z")

</div>

和你相同的图片，这是我的加载时间。

 ![截屏2023-10-01 20.58.31](https://forumcdn.freemdict.com/uploads/default/original/3X/f/d/fd5d30db56ffed196307bd552e4969e4b0345d27.png)

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 13:16 UTC](https://forum.freemdict.com/t/topic/23713/31 "2023-10-01T13:16:11Z")

</div>

也许是硬盘的差异。我硬盘用的PCIe 3.0的接口，可能你是SATA的接口。不知道谁用的PCIe 4.0的接口，也可以来截图看看。

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 13:25 UTC](https://forum.freemdict.com/t/topic/23713/32 "2023-10-01T13:25:44Z")

</div>

我就是PCIe 4.0的SSD，应该不是文件读取的问题

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年10 月 1 日 13:29 UTC](https://forum.freemdict.com/t/topic/23713/33 "2023-10-01T13:29:12Z")

</div>

我的是M.2接口SSD固态硬盘

---

<div class="post-metadata">

作者： ![glacierlee](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/glacierlee/32/96873_2.png) [@glacierlee](https://forum.freemdict.com/u/glacierlee)\
发布日期： [2023 年10 月 1 日 13:30 UTC](https://forum.freemdict.com/t/topic/23713/34 "2023-10-01T13:30:40Z")

</div>

如果电脑上有VPN的话，不妨把VPN禁用试试看，之前发现VPN会拦截本地的流量从而造成资源加载缓慢

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 13:37 UTC](https://forum.freemdict.com/t/topic/23713/35 "2023-10-01T13:37:13Z")

</div>

你的硬盘比我的还好，可能还有其他原因，按楼上说的关了代理看看。

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 13:59 UTC](https://forum.freemdict.com/t/topic/23713/36 "2023-10-01T13:59:07Z")

</div>

VPN的开关没感受到影响，但发现一个奇怪的事：图片加载速度与GoldenDict的窗口大小有关，全屏的状态下图片的加载速度在300ms以内，正常查词窗口大小状态下速度则在600ms左右

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 14:34 UTC](https://forum.freemdict.com/t/topic/23713/37 "2023-10-01T14:34:23Z")

</div>

进到我知识盲区了，这个问题要咨询 @xiaoyifang 和 @slbtty 。关键还是 522kB 的图片，耗时 719ms 加载，我觉得很不正常。另外速度有问题的请求都来自 bres 和 qrc 两个协议，而 gdlookup 的请求保持了和官方原版一样的速度。

---

<div class="post-metadata">

作者： ![hua](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/hua/32/11090_2.png) [@hua](https://forum.freemdict.com/u/hua)\
发布日期： [2023 年10 月 1 日 14:58 UTC](https://forum.freemdict.com/t/topic/23713/38 "2023-10-01T14:58:15Z")

</div>

官方版是不是就没有问题？

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 15:23 UTC](https://forum.freemdict.com/t/topic/23713/39 "2023-10-01T15:23:44Z")

</div>

对，试了下官方QT5版，除了文字太小没自适应4k屏外，加载速度快出天际（20ms以内）

 ![image](https://forumcdn.freemdict.com/uploads/default/original/3X/0/d/0d8f28812a8a4d6a12d21445b77ecc53f41535b2.png)

 ![image](https://forumcdn.freemdict.com/uploads/default/original/3X/b/e/be9a67eaaefa6665a819c5577c156a7ab206df75.jpeg)

---

<div class="post-metadata">

作者： ![slbtty](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/slbtty/32/19175_2.png) [@slbtty](https://forum.freemdict.com/u/slbtty)\
发布日期： [2023 年10 月 1 日 21:06 UTC](https://forum.freemdict.com/t/topic/23713/41 "2023-10-01T21:06:16Z")

</div>

试了一下，这个 mdx 词典的图片在我的电脑上需要 70ms~100ms [https://github.com/goldendict/goldendict/files/12767768/test.zip](https://github.com/goldendict/goldendict/files/12767768/test.zip) 同样的一张图片改成 DSL 耗时差不多 [test\_dsl.zip](https://forum.freemdict.com/uploads/short-url/64qABy35jGPGIO7UyXNFyEN6tJ3.zip) (1.9 MB) ，应该和词典格式没有关系。

用类似 GD 的 `bres://` 那样注册一个 url handler 单纯读取图片数据传递给 QtWebengine 而不做其它任何事情，需要 5~20ms ，这部分时间没有办法 [GitHub - SourceReviver/qt\_webengine\_custom\_schema\_load\_img](https://github.com/SourceReviver/qt_webengine_custom_schema_load_img)

我觉得加载图片速度确实有问题，而且有不小的优化空间，但是具体哪里出问题了需要分析一波代码。

[上一页](https://forum.freemdict.com/t/topic/23713.md?page=1)

[下一页](https://forum.freemdict.com/t/topic/23713.md?page=3)
