himselfv / wakan

Japanese and Chinese learning tool with dictionary
39 stars 7 forks source link

Profile and optimize Wakan loading time #111

Closed himselfv closed 11 years ago

himselfv commented 11 years ago

Original report by me.

Originally reported on Google Code with ID 111

Run Wakan while profiling it with Process Monitor. Note that every registry key is read
3 times in a row!

Turns out, TRegistryIniFile does this in 3 steps:
1. QueryKey() to establish key data type. Check that it is String.
2. Call ReadString to get data:
2a. QueryKey() to establish key data type. Check that it is String. (Yep, another time)
2b. QueryKey() to get data.

All of this could have been handled by a single QueryKey with subsequent check for
data type returned.

This is not critical, but in an effort to make Wakan start faster, reimplementing TRegistryIniFile
could probably help.

Reported by himselfv on 2013-02-08 13:07:37

himselfv commented 11 years ago
*Turning this Issue into generic optimization one.

Wakan.cfg is read in 128 byte chunks. Each read is a kernel call => spends time.
Read it all at once, then process in memory.

Reported by himselfv on 2013-02-08 13:08:58

himselfv commented 11 years ago
When optimizing Packages/TextTables, also optimize PkgWrite which uses the same strange
buffering system

Reported by himselfv on 2013-02-08 13:16:00

himselfv commented 11 years ago
Major time when loading was spent on reading packages, again and again, in small chunks.
Headers are read in 1 byte/337 byte reads, then data in 2000 byte reads.

This was mitigated by using a cached reader with a cache of 1Mb. It's pretty efficient
so now it's only a few reads and a lot less time spent.

This was not really a "fix" because packages are still inefficient, they're just cached
now. If I ever care to make this right, I guess I'll need to rewrite package code to
first read whole header and work on it in memory, then to read contained files in large
chunks (ideally, to read the whole file in one operation, but this might not be possible
if there's no size prefix)

Reported by himselfv on 2013-02-11 09:00:28

himselfv commented 11 years ago

Reported by himselfv on 2013-02-18 13:20:17