Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Perfect Local Mirror 本地编译缓存加速器

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X License Apache PerfectlySoft Twitter Slack Status

We received many complaints about how slow Swift Package Manager version 4 was, so here is an example of cheating sheet - to accelerate your Perfect App by caching all heavy dependencies.

我们收到大量关于Swift 4 SPM 软件包管理器速度过慢的投诉,因此本项目用于Perfect编译加速

Quick Start

Install

Open a terminal then execute the following script.

打开终端执行下列命令:

git clone https://github.com/PerfectlySoft/Perfect-LocalMirror.git && \
./Perfect-LocalMirror/install.sh

⚠️ NOTE 注意 ⚠️ You may need sudo privilege to perform the installation.

您可能需要管理员权限以执行上述命令。

Perfect Assistant Support

There is also a script to patch Perfect Assistant to use these mirrors:

本程序同样包括了用于软件助手的补丁。

./Perfect-LocalMirror/updatePA.sh

You can revert the patch by another script:

您可以随时卸载这个补丁:

./Perfect-LocalMirror/resetPA.sh

Usage

You will find a localized version of PerfectTemplate, the starter web server, under the folder of /private/var/perfect/PerfectTemplate:

您会发现一个本地版本的模板服务器,结构已经发生了显著变化:

import PackageDescription
let package = Package(
	name: "PerfectTemplate",
	targets: [],
	dependencies: [
		.Package(url: "/private/var/perfect/Perfect-HTTPServer", majorVersion: 3),
	]
)

Then the server building speed will be completely different now.

现在服务器编译速度肯定大不相同了,请尽情尝试!

Local Cache Path

Now these components are available on local repo /private/var/perfect as the above fashion: 目前可以使用上述路径的本地模块包括:

(a full example can be found on test.sh script) (完整的调用样例可以参考 test.sh 脚本)

PerfectLib PerfectHTTP PerfectHTTPServer PerfectThread
PerfectLogger PerfectRequestLogger PerfectNet LinuxBridge
PerfectXML PerfectCrypto PerfectCURL PerfectSMTP
PerfectMustache PerfectPostgreSQL PerfectSQLite PerfectMySQL
PerfectRedis PerfectMongoDB PerfectRepeater PerfectNotifications
PerfectCouchDB PerfectFileMaker PerfectHadoop PerfectWebSockets
PerfectWebRedirects PerfectPython PerfectMarkdown PerfectLDAP
PerfectKafka PerfectMosquitto PerfectSession PerfectSessionMySQL
PerfectSessionPostgreSQL PerfectSessionRedis PerfectSessionMongoDB PerfectSessionSQLite
PerfectSessionCouchDB PerfectTurnstileSQLite PerfectTurnstileMySQL PerfectTurnstilePostgreSQL
PerfectTurnstileMongoDB PerfectTurnstileCouchDB PerfectLocalAuthentication PerfectZip
OAuth2 MariaDB SwiftMoment SwiftRandom
SwiftString JSONConfig StORM SQLiteStORM
CouchDBStORM PostgresStORM MySQLStORM MongoDBStORM
PerfectLocalAuthentication      

** NOTE ** If any Server Side Swift component has little dependencies and free of incompressible large files such as binaries in git history, then it could be unnecessary to cache it as the above. ⚠️注意⚠️ 如果Swift服务器组件没有特别的依存关系,而且在历史版本中也没有无法压缩的大文件(比如二进制文件),那么可能就根本没有必要使用这个本地缓存

Magic Behind

The actual bottleneck is Swift Package Manager version 4 is using a --mirror flag of git clone, which has a good reason but may cause 8x+ slower than Swift 3 in a certain situation.

我们发现瓶颈存在于上述链接,即 2017年2月27日 之后在git clone 命令中增加了--mirror标志。这个想法是好的,但是极端情况下会导致编译速度慢八倍。

The solution is simple: build a local cache of each repo recursively and truncate unnecessary backlog history resulted by --mirror prior to swift package resolve.

解决思路其实很简单,就是在SPM解析之前,首先把经过截取不必要版本历史的简化镜像置于本地硬盘。

Only three steps it actually takes.

实际这个过程就三步:

  • mirror_ex RepoName VenderName which will grab the latest version from github. 首先是从 github 上取得目标最新版本。
  • Patch Package.swift to allow local mirrors. 然后修改本地下载的Package.swift 文件以应用本地镜像。
  • git tag the latest online version to the offline updates. 在修改基础上增加一个和在线版本一致的离线版本。

Take OAuth2 for example, the installation will patch all dependencies to offline versions. By default, the installation path is HUB=/private/var/perfect. 以 OAuth2 为例,安装脚本会将所有依存关系指向本地离线版本,默认安装路径是 HUB=/private/var/perfect

mirror Perfect-OAuth2
tee Package.swift << EOF >> /dev/null
import PackageDescription
let package = Package(name: "OAuth2",	targets: [],
	dependencies: [
		.Package(url: "$HUB/Perfect-Session", majorVersion: 3)
	])
EOF
reversion

You can add as many components as possible to the script. Have fun!

您可以尽情按照上述风格自行向脚本追加需要的 Swift 组件,慢用!

Further Information

For more information on the Perfect project, please visit perfect.org.

微信好友圈

You can’t perform that action at this time.