SourceForge has been redesigned. Learn more.

#616 Tcl interpreter pkgIndex 'cache' - new version


This is a follow-up of ticket ID 680169 "Tcl interpreter pkgIndex 'cache'". Please find attached a modified version of the patch. Description is in the previous ticket.
Please comment.


  • Etienne Basilik

    Etienne Basilik - 2012-05-02

    New version of cache patch that caches paths to pkgIndex.tcl rather than [ifneeded] scripts

  • Etienne Basilik

    Etienne Basilik - 2012-05-14

    I have improved the patch. Please find attached packages_cache_improved.tcl.

    1- Removed the cache file from [info library]. This was an error I think. The cache is already user and machine specific so it is useless to put it in a shared location. But worse: writing it to [info library] makes the cache copy itself on all computers, and for all Tcl installations! E.g. suppose there are 2 versions of Tcl installed on a network drive (A and B) and that everyone uses version A. If one person executes version B once, its local cache will be updated with B's packages. Then, when using A again, this local B-specific cache will get copied to A's [info library] and from there to all other users home directory...

    2- Read the cache file once per Tclsh invocation, except when auto_path has changed.

    3- Avoided writing the cache file each time tcl::PackageIndexCache is invoked. Only write it when the [package unknown] search have found something new. Indeed, some packages (as md5) depend optionnaly on other packages which are not installed by default in ActiveState Tcl. [package require md5] hence always searches for 3 packages that are not there. Writing the cache each time is a time spoil.

    With these changes, Tcl now not only starts faster when installed on a network drive, but also when installed locally. See by yourself. Measures taken with a fresh ActiveState Tcl 8.6b7 installation on C:\ drive on Wiindows:

    Without patch:
    time {package require tdom}: 64ms
    time {package require md5}: 102ms
    time {package require Tclx}: 48ms

    With the patch:
    time {package require tdom}: 42ms
    time {package require md5}: 114ms
    time {package require Tclx}: 18ms

    And the starup time of Tclsh.exe itself is quite the same with and without the patch (my measure tool for this is not very good, so to be confirmed by someone).

    Only md5 is slower, but only by 11%... But again, this is because md5 depends on tcllibc. If tcllibc is installed, load time with the patch drops below time without patch.

    At this point, couldn't this patch be integrated OFFICIALLY into Tcl releases? [package require] is just faster than normal Tcl! Or we way consider to ask the user at installation if he wants that cache feature, and strongly recommend it if Tcl is not installed locally.