libxbps: performance improvements by caching the most accessed paths.

1- We can cache the result of the first xbps_pkgdb_init() when it fails
   and avoid the malloc/free/access from it.
2- We cache the uname(2) result into a private var in xbps_handle and
   use it in xbps_pkg_arch_match().

This improves performance by ~5% approx and it's close as it was before
introducing the repository index format 1.5.
This commit is contained in:
Juan RP
2012-06-15 15:33:11 +02:00
parent 506625a716
commit 068cab8d20
22 changed files with 272 additions and 159 deletions

View File

@@ -168,7 +168,7 @@ remove_stale_entries_in_reqby(struct xbps_handle *xhp,
}
printf("%s: found stale entry in requiredby `%s' (fixed)\n",
crd->pkgver, str);
if (xbps_remove_string_from_array(crd->pkgd_reqby, str))
if (xbps_remove_string_from_array(xhp, crd->pkgd_reqby, str))
needs_update = true;
}
if (needs_update) {

View File

@@ -49,7 +49,7 @@ list_pkgs_in_dict(struct xbps_handle *xhp,
(void)loop_done;
chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, NULL))
if (chkarch && !xbps_pkg_arch_match(xhp, arch, NULL))
return 0;
if (lpc->check_state) {

View File

@@ -39,7 +39,9 @@ struct ffdata {
};
static void
match_files_by_pattern(prop_dictionary_t pkg_filesd, struct ffdata *ffd)
match_files_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t pkg_filesd,
struct ffdata *ffd)
{
prop_array_t array;
const char *filestr, *pkgver, *arch;
@@ -47,7 +49,7 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, struct ffdata *ffd)
int x;
prop_dictionary_get_cstring_nocopy(pkg_filesd, "architecture", &arch);
if (!xbps_pkg_arch_match(arch, NULL))
if (!xbps_pkg_arch_match(xhp, arch, NULL))
return;
array = prop_dictionary_get(pkg_filesd, "files");
@@ -94,7 +96,7 @@ find_files_in_package(struct xbps_handle *xhp,
ffd->repouri = rpi->uri;
for (i = 0; i < prop_array_count(idxfiles); i++)
match_files_by_pattern(prop_array_get(idxfiles, i), ffd);
match_files_by_pattern(xhp, prop_array_get(idxfiles, i), ffd);
prop_object_release(idxfiles);
return 0;

View File

@@ -56,7 +56,7 @@ rmobsoletes_files_cb(struct xbps_handle *xhp,
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (xbps_find_pkg_in_array_by_pkgver(ifd->idx, pkgver, arch)) {
if (xbps_find_pkg_in_array_by_pkgver(xhp, ifd->idx, pkgver, arch)) {
/* pkg found, do nothing */
return 0;
}
@@ -95,7 +95,7 @@ genindex_files_cb(struct xbps_handle *xhp,
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (xbps_find_pkg_in_array_by_pkgver(ifd->idxfiles, pkgver, arch)) {
if (xbps_find_pkg_in_array_by_pkgver(xhp, ifd->idxfiles, pkgver, arch)) {
fprintf(stderr, "index-files: skipping `%s' (%s), "
"already registered.\n", pkgver, arch);
return 0;
@@ -278,7 +278,7 @@ repo_genindex_files(struct xbps_handle *xhp, const char *pkgdir)
}
arch = strchr(p, ',') + 1;
if (!xbps_remove_pkg_from_array_by_pkgver(
ifd->idxfiles, pkgver, arch)) {
xhp, ifd->idxfiles, pkgver, arch)) {
free(pkgver);
rv = EINVAL;
goto out;

View File

@@ -129,7 +129,8 @@ repoidx_get(struct xbps_handle *xhp, const char *pkgdir)
}
static int
add_binpkg_to_index(prop_array_t idx,
add_binpkg_to_index(struct xbps_handle *xhp,
prop_array_t idx,
const char *filedir,
const char *file)
{
@@ -165,7 +166,7 @@ add_binpkg_to_index(prop_array_t idx,
* than current registered package, update the index; otherwise
* pass to the next one.
*/
curpkgd = xbps_find_pkg_in_array_by_name(idx, pkgname, arch);
curpkgd = xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, arch);
if (curpkgd == NULL) {
if (errno && errno != ENOENT) {
prop_object_release(newpkgd);
@@ -236,7 +237,8 @@ add_binpkg_to_index(prop_array_t idx,
goto out;
}
free(oldfilepath);
if (!xbps_remove_pkg_from_array_by_pkgver(idx, buf, oldarch)) {
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
buf, oldarch)) {
xbps_error_printf("failed to remove `%s' "
"from plist index: %s\n", buf, strerror(errno));
prop_object_release(newpkgd);
@@ -350,7 +352,7 @@ repo_genindex(struct xbps_handle *xhp, const char *pkgdir)
rv = errno;
goto out;
}
rv = add_binpkg_to_index(idx, curdir, binfile);
rv = add_binpkg_to_index(xhp, idx, curdir, binfile);
free(binfile);
if (rv == EEXIST) {
rv = 0;

View File

@@ -108,7 +108,7 @@ show_pkg_namedesc(struct xbps_handle *xhp,
(void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (!xbps_pkg_arch_match(arch, NULL))
if (!xbps_pkg_arch_match(xhp, arch, NULL))
return 0;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);