Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 1b9b1a8c8a17a2fd15c0783734c617d3ce3cea48
Ticket: 3519865fffffffffffffffffffffffffffffffff
[package require] is too slow
User & Date: basilik99 on 2012-04-24 22:56:20
Changes

  1. icomment:
    Hi,
    
    I use Tcl 8.6.0.0.b6.
    
    dgp said:
    "Trying to convert [package require] to something event-driven is a contradiction in terms"
    I didn't meant running [package require] in the event loop (and then waiting for its completion using update or vwait). My first idea was really about it running in a different thread, but at the level of Tcl core. Again, when Tcl core commands asks information to the OS (Windows in my case), the tclsh process is suspended while the system call executes. That time could be used by the Tcl core to terminate non-I/O related commands such as [package require].
    
    Now, for the ideas posted, here is the time for loading tdom package alone:
    % time {package require tdom}
    3294262 microseconds per iteration
    
    Then I tried what you recommended (using load/source directly):
    % set dir {some_directory/lib/teapot/package/win32-ix86/lib/tdom0.8.3}
    % time {load [list [file join $dir tdom083.dll]]; source [list [file join $dir tdom.tcl]]}
    2260355 microseconds per iteration
    
    This is saving 1 second. Its good, but not enough. It does not worth hardcoding the paths.
    
    I also tried to do both [package require] in a separate thread:
    
    package require Thread
    set tdom_md5_thread [thread::create]
    thread::send -async $tdom_md5_thread {package require tdom}
    thread::send -async $tdom_md5_thread {package require md5}
    
    ... search in directories here while the 2 [package require] are performed ...
    
    thread::send -async $tdom_md5_thread "set file_to_check $file_to_check"
    
    thread::send -async $tdom_md5_thread \
    {
       set xrd_in [open $file_to_check r]
       dom parse -simple [read $xrd_in] xrd_dom_tree
       close $xrd_in
       set xrd_first_title0_node [lindex [$xrd_dom_tree selectNodes {XROD//APIDOC//TITLE[@LEVEL='0']}] 0]
       return "[$xrd_first_title0_node asText].ptu"
    } ptu_name
    
    ... some code ...
    vwait ptu_name
    
    It works, but I doubt that I am really gaining time. One reason is the time to initialize the thread:
    % time {package require Thread}
    1633521 microseconds per iteration
    % time {thread::create}
    972502 microseconds per iteration
    
    But also this complexifies my script. Anyway, thanks for posting this idea as it may be useable in other situations.
    
    Etienne
    
    
  2. login: "basilik99"
  3. mimetype: "text/plain"
  4. username: "basilik99"