summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-09-09 15:25:05 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-09-09 15:45:11 +0200
commitefe11290ae3c71d2a7a3735c265ff22a0cf92921 (patch)
treed8901f92910bba6500ab04a29aecb2703308c81d /lib/App/BorgRestore
parentb5243a148a9ac8b9abcbf0ae0b27046b153a835b (diff)
downloadApp-BorgRestore-efe11290ae3c71d2a7a3735c265ff22a0cf92921.tar.gz
App-BorgRestore-efe11290ae3c71d2a7a3735c265ff22a0cf92921.tar.xz
PathTimeTable/DB: Improve performance by removing usage of regex in hot places
This cuts execution time on my workstation from about 85 seconds for an --update-cache adding one archive to roughly 62 seconds. Measured totally unscientifically by simply running the full application instead of isolating the code, but it makes sense that regexes are slower so I'll take it. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/BorgRestore')
-rw-r--r--lib/App/BorgRestore/PathTimeTable/DB.pm16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/App/BorgRestore/PathTimeTable/DB.pm b/lib/App/BorgRestore/PathTimeTable/DB.pm
index 1a24999..b0c0bb8 100644
--- a/lib/App/BorgRestore/PathTimeTable/DB.pm
+++ b/lib/App/BorgRestore/PathTimeTable/DB.pm
@@ -43,15 +43,19 @@ method set_archive_id($archive_id) {
method add_path($path, $time) {
$self->{stats}->{total_paths}++;
my $old_cache_path = $self->{current_path_in_cache};
- while ($old_cache_path =~ m#/#) {
- unless ($path =~ m#^\Q$old_cache_path\E/#) {
- delete $self->{cache}->{$old_cache_path};
+ while ((my $slash_index = rindex($old_cache_path, "/")) != -1) {
+ $self->{stats}->{cache_invalidation_loop_iterations}++;
+ if ($old_cache_path eq substr($path, 0, length($old_cache_path))) {
+ # keep the cache content for the part of the path that stays the same
+ last;
}
- $old_cache_path =~ s|/[^/]*$||;
+ delete $self->{cache}->{$old_cache_path};
+ # strip last part of path
+ $old_cache_path = substr($old_cache_path, 0, $slash_index);
}
my $full_path = $path;
- while ($path =~ m#/#) {
+ while ((my $slash_index = rindex($path, "/")) != -1) {
$self->_add_path_to_db($self->{archive_id}, $path, $time);
my $cached = $self->{cache}->{$path};
if ($path ne $full_path && (!defined $cached || $cached < $time)) {
@@ -60,7 +64,7 @@ method add_path($path, $time) {
#$log->tracef("Setting cache time for path '%s' to %d", $path, $time);
$self->{cache}->{$path} = $time;
}
- $path =~ s|/[^/]*$||;
+ $path = substr($path, 0, $slash_index);
}
$self->_add_path_to_db($self->{archive_id}, $path, $time) unless $path eq ".";
my $cached = $self->{cache}->{$path};