Skip to content

Commit

Permalink
Add I/O caching for the FreeBSD backend.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arrowd committed May 15, 2023
1 parent 7d5c208 commit a17846f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/asgen/backends/freebsd/fbsdpkg.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private:
string pkgFname;
PackageKind _kind;

ArchiveDecompressor pkgArchive;
string[] contentsL = null;

public:
this (string pkgRoot, JSONValue[string] j)
{
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/asgen/backends/freebsd/fbsdpkgindex.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down

0 comments on commit a17846f

Please sign in to comment.