From 034e4c632aab3fc422a016310fcf60dd6918649e Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Tue, 14 Mar 2023 08:23:26 +0300 Subject: [PATCH] Add I/O caching for the FreeBSD backend. This reduces the running time considerably when processing large packages like LLVM and Plasma Workspace. The implementation follows ideas from other backends. Sponsored by: Serenity Cybersecurity, LLC --- src/asgen/backends/freebsd/fbsdpkg.d | 21 ++++++++++++--------- src/asgen/backends/freebsd/fbsdpkgindex.d | 13 ++++++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/asgen/backends/freebsd/fbsdpkg.d b/src/asgen/backends/freebsd/fbsdpkg.d index 03d870a..4eb3f84 100644 --- a/src/asgen/backends/freebsd/fbsdpkg.d +++ b/src/asgen/backends/freebsd/fbsdpkg.d @@ -38,6 +38,9 @@ private: string pkgFname; PackageKind _kind; + ArchiveDecompressor pkgArchive; + string[] contentsL = null; + public: this (string pkgRoot, JSONValue[string] j) { @@ -70,23 +73,23 @@ public: override const(ubyte[]) getFileData (string fname) { - ArchiveDecompressor ad; - ad.open (pkgFname); + if (!pkgArchive.isOpen) + pkgArchive.open (this.getFilename); - return ad.readData(fname); + return pkgArchive.readData(fname); } @property override string[] contents () { - ArchiveDecompressor ad; - ad.open (pkgFname); - - auto c = ad.readContents(); + if (!this.contentsL.empty) + return this.contentsL; - //throw new Exception(join(c, "\n")); + if (!pkgArchive.isOpen) + pkgArchive.open (this.getFilename); - return c; + this.contentsL = pkgArchive.readContents (); + return this.contentsL; } override diff --git a/src/asgen/backends/freebsd/fbsdpkgindex.d b/src/asgen/backends/freebsd/fbsdpkgindex.d index 6e28037..03f49b5 100644 --- a/src/asgen/backends/freebsd/fbsdpkgindex.d +++ b/src/asgen/backends/freebsd/fbsdpkgindex.d @@ -56,7 +56,7 @@ public: pkgCache = null; } - Package[] packagesFor (string suite, string section, string arch, bool withLongDescs = true) + private Package[] loadPackages (string suite, string section, string arch) { auto pkgRoot = buildPath (rootDir, suite); auto listsTarFname = buildPath (pkgRoot, "packagesite.pkg"); @@ -81,6 +81,17 @@ public: return pkgs.data; } + Package[] packagesFor (string suite, string section, string arch, bool withLongDescs = true) + { + immutable id = "%s-%s-%s".format (suite, section, arch); + if (id !in pkgCache) { + auto pkgs = loadPackages (suite, section, arch); + synchronized (this) pkgCache[id] = pkgs; + } + + return pkgCache[id]; + } + Package packageForFile (string fname, string suite = null, string section = null) { return null; // FIXME: not implemented