Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Performance of _store_cache and _retrieve_cache



On Feb 8,  5:19pm, Daniel Hahler wrote:
}
} _store_cache saves the array like this:
} 
}     _zsh_all_pkgs=( '02exercicio' '0x10c-asm'  ... )
} 
} The problem is that `source ./pip_allpkgs.slow` takes about 8 seconds,
} and is slower than generating the list anew!

The slowdown here appears to be with compiling the source'd file into
the internal wordcode format before executing it.  Even dumping the
whole assignment as a single string and then using "eval" on that, is
faster than allowing "source" to parse the words directly.  We may
want to dig further into why that is the case.

The following is a LOT faster than either "source" or "eval", but may
require recent changes that fix bugs in the parsing of $(...) :

_zsh_all_pkgs=( "${(zQ)$(<<\EO:_zsh_all_pkgs
'02exercicio' '0x10c-asm' ...
EO:_zsh_all_pkgs
)}" )


diff --git a/Completion/Base/Utility/_store_cache b/Completion/Base/Utility/_store_cache
index 86e72e9..8feaee6 100644
--- a/Completion/Base/Utility/_store_cache
+++ b/Completion/Base/Utility/_store_cache
@@ -46,8 +46,15 @@ if zstyle -t ":completion:${curcontext}:" use-cache; then
   for var; do
     case ${(Pt)var} in
     (*readonly*) ;;
-    (*(association|array)*) print -r "$var=( ${(kv@Pqq)^^var} )";;
-    (*)                     print -r "$var=${(Pqq)^^var}";;
+    (*(association|array)*)
+	# Dump the array as a here-document to reduce parsing overhead
+	# when reloading the cache with "source" from _retrieve_cache
+	print -r "$var=( "'"${(zQ)$(<<\EO:'"$var"
+	print -r "${(kv@Pqq)^^var}"
+	print -r "EO:$var"
+	print -r ')}" )'
+	;;
+    (*) print -r "$var=${(Pqq)^^var}";;
     esac
   done >! "$_cache_dir/$_cache_ident"
 else



Messages sorted by: Reverse Date, Date, Thread, Author