diff options
| author | ruki <[email protected]> | 2019-05-24 22:35:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-05-24 09:30:18 +0800 |
| commit | 18135dbc217d1ab00baf4544ddf73564a723e388 (patch) | |
| tree | 48a6ce701490d8b887efdb3810361cde7f6a0abf | |
| parent | db1994fef8d6425e710bb9a99694ff80eead41aa (diff) | |
optimize loadfile again, decreate 98% startup time
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | xmake/core/_xmake_main.lua | 20 |
2 files changed, 16 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b345629d..f1f3ad3e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ * Improve remote package manager * Improve `target:on_xxx` scripts to support to match `android|armv7-a@macosx,linux|x86_64` pattern -* Improve loadfile to optimize startup speed +* Improve loadfile to optimize startup speed, decrease 98% time ### Bugs fixed @@ -596,7 +596,7 @@ * 改进远程依赖包管理,丰富包仓库 * 改进`target:on_xxx`自定义脚本,去支持匹配`android|armv7-a@macosx,linux|x86_64`模式 -* 改进loadfile,优化启动速度,windows上启动xmake提速30% +* 改进loadfile,优化启动速度,windows上启动xmake时间提速98% ### Bugs修复 diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 760ea4dc8..7833e1687 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -34,14 +34,22 @@ xmake._PROJECT_FILE = "xmake.lua" local _loadfile = _loadfile or loadfile local _loadcache = {} function loadfile(filepath) - local errors = nil - local script = _loadcache[filepath] - if script == nil then - script, errors = _loadfile(filepath) - if script and filepath:startswith(_PROGRAM_DIR) then - _loadcache[filepath] = script + + -- attempt to load script from cache first + local mtime = nil + local cache = _loadcache[filepath] + if cache and cache.script then + mtime = os.mtime(filepath) + if mtime > 0 and cache.mtime == mtime then + return cache.script, nil end end + + -- load script from file + local script, errors = _loadfile(filepath) + if script then + _loadcache[filepath] = {script = script, mtime = mtime or os.mtime(filepath)} + end return script, errors end |
