From 64a5fd37271a3e454c0d59ac3500e1a1b232e4f7 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Sat, 13 Apr 2019 11:48:58 +0200 Subject: gpg: New caching functions. * g10/objcache.c: New. * g10/objcache.h: New. * g10/Makefile.am (common_source): Add them. * g10/gpg.c: Include objcache.h. (g10_exit): Call objcache_dump_stats. * g10/getkey.c: Include objcache.h. (get_primary_uid, release_keyid_list): Remove. (cache_user_id): Remove. (finish_lookup): Call the new cache_put_keyblock instead of cache_user_id. (get_user_id_string): Remove code for mode 2. (get_user_id): Implement using cache_get_uid_bykid. -- This generic caching module is better than the ad-hoc code we used in getkey.c. More cleanup in getkey is still required but it is a start. There is also a small performance increase with the new cache: With a large keyring and --list-sigs I get these numbers: | | before | after | |------+------------+------------| | real | 14m1.028s | 12m16.186s | | user | 2m18.484s | 1m36.040s | | sys | 11m42.420s | 10m40.044s | Note the speedup in the user time which is due to the improved cache algorithm. This is obvious, because the old cache was just a long linked list; the new cache are two hash tables. Signed-off-by: Werner Koch --- g10/objcache.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 g10/objcache.h (limited to 'g10/objcache.h') diff --git a/g10/objcache.h b/g10/objcache.h new file mode 100644 index 000000000..e92679168 --- /dev/null +++ b/g10/objcache.h @@ -0,0 +1,28 @@ +/* objcache.h - Caching functions for keys and user ids. + * Copyright (C) 2019 g10 Code GmbH + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef GNUPG_G10_OBJCACHE_H +#define GNUPG_G10_OBJCACHE_H + +void objcache_dump_stats (void); +void cache_put_keyblock (kbnode_t keyblock); +char *cache_get_uid_bykid (u32 *keyid, unsigned int *r_length); + +#endif /*GNUPG_G10_OBJCACHE_H*/ -- cgit v1.2.3