Changeset 11064


Ignore:
Timestamp:
03/11/10 03:32:39 (2 years ago)
Author:
adamk
Message:

Landing the slave master quick-spawn change, which reduces average memory cost of Padre by 25%

Location:
trunk/Padre
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/Changes

    r11058 r11064  
    33 
    440.59 To Be Released 
    5     - Don't crash open file list dialog on unsaved files or without files 
    6       (SEWI) 
     5    - Don't crash open file list dialog on unsaved files or without 
     6      files (SEWI) 
    77    - Added a small survey for new Padre installation (SEWI) 
    88    - Resolved the clash between threads and SQLite by temporarily 
    99      disconnecting from SQLite during a thread spawn (ADAMK) 
    10     - Move the slave driver spawn into Padre::Startup, so that 
    11       we get much much smaller thread spawn memory penalty from the 
    12       interpreter copy (ADAMK) 
     10    - Slave master quick-spawning in Padre::Startup, so that 
     11      we get smaller thread spawn memory penalty from the 
     12      interpreter copy. On Win32 the per-thread cost drops from 
     13      34.1meg to 20meg with a reduction in total memory use for a 
     14      typical user of about 20% (ADAMK) 
    1315 
    14160.58 2010.03.08 
  • trunk/Padre/lib/Padre.pm

    r11029 r11064  
    149149    # Create the main window 
    150150    require Padre::Wx::App; 
    151     $self->{wx} = Padre::Wx::App->new($self); 
     151    $self->{wx} = Padre::Wx::App->create($self); 
    152152 
    153153    # Create the task manager 
     
    158158 
    159159    # Create the action queue 
    160     $self->{actionqueue} = Padre::Action::Queue->new(); 
     160    $self->{actionqueue} = Padre::Action::Queue->new; 
    161161 
    162162    # Startup completed, let go of the database 
  • trunk/Padre/lib/Padre/SlaveDriver.pm

    r11056 r11064  
    8080 
    8181        # Wx must be loaded before this code fires 
     82        require Wx; 
    8283        require Wx::Event; 
    8384        $TASK_DONE_EVENT  = Wx::NewEventType() unless defined $TASK_DONE_EVENT; 
     
    123124 
    124125sub spawn { 
    125     my $self         = shift; 
    126     my $task_manager = shift; 
     126    my $self    = shift; 
     127    my $manager = shift; 
    127128 
    128129    require Storable; 
    129130    $self->{cmd_queue}->enqueue( 
    130         Storable::freeze( [ $task_manager->task_queue ] ) 
     131        Storable::freeze( [ $manager->task_queue ] ) 
    131132    ); 
    132133 
     
    194195    @_ = (); # Hack to avoid "Scalars leaked" 
    195196 
    196     require Storable; 
    197     require Padre::TaskManager; 
    198  
    199     # Set the thread-specific main-window pointer 
    200     my $wx = Padre->ide->wx; 
    201  
    202     # warn threads->tid() . " -- Hi, I'm a thread."; 
    203  
    204     while ( my $frozen_task = $queue->dequeue ) { 
    205  
    206         # warn threads->tid() . " -- got task."; 
     197    # warn threads->tid . " -- Hi, I'm a thread."; 
     198 
     199    # Hold a pointer to the global application root 
     200    require Padre::Wx::App; 
     201    my $wx = Padre::Wx::App->new; 
     202 
     203    while ( my $frozen = $queue->dequeue ) { 
     204 
     205        # warn threads->tid . " -- got task."; 
    207206 
    208207        # warn("THREAD TERMINATING"), return 1 if not ref($task) and $task eq 'STOP'; 
    209         return 1 if not ref($frozen_task) and $frozen_task eq 'STOP'; 
    210  
    211         my $task = Padre::Task->deserialize( \$frozen_task ); 
     208        return 1 if not ref($frozen) and $frozen eq 'STOP'; 
     209 
     210        require Padre::Task; 
     211        my $task = Padre::Task->deserialize( \$frozen ); 
    212212        $task->{__thread_id} = threads->tid; 
    213213 
    214         my $thread_start_event = Wx::PlThreadEvent->new( 
     214        my $before = Wx::PlThreadEvent->new( 
    215215            -1, 
    216216            $TASK_START_EVENT, 
    217217            $task->{__thread_id} . ";" . ref($task), 
    218218        ); 
    219         Wx::PostEvent( $wx, $thread_start_event ); 
     219        Wx::PostEvent( $wx, $before ); 
    220220 
    221221        # RUN 
     
    223223 
    224224        # FREEZE THE PROCESS AND PASS IT BACK 
    225         undef $frozen_task; 
    226         $task->serialize( \$frozen_task ); 
    227  
    228         my $thread_done_event = Wx::PlThreadEvent->new( 
     225        undef $frozen; 
     226        $task->serialize( \$frozen ); 
     227 
     228        my $after = Wx::PlThreadEvent->new( 
    229229            -1, 
    230230            $TASK_DONE_EVENT, 
    231             $frozen_task, 
     231            $frozen, 
    232232        ); 
    233         Wx::PostEvent( $wx, $thread_done_event ); 
    234  
    235         # warn threads->tid() . " -- done with task."; 
     233        Wx::PostEvent( $wx, $after ); 
     234 
     235        # warn threads->tid . " -- done with task."; 
    236236    } 
    237237} 
    238238 
    239239sub _slave_driver_loop { 
    240     my ( $inqueue, $outqueue ) = @_; 
    241     @_ = (); # hack to avoid "Scalars leaked" 
    242  
    243     while ( my $args = $inqueue->dequeue ) { # args is frozen [$main, $queue] 
     240    my ( $in, $out ) = @_; 
     241    @_ = (); # Hack to avoid "Scalars leaked" 
     242 
     243    while ( my $args = $in->dequeue ) { # args is frozen [$main, $queue] 
    244244        last if $args eq 'STOP'; 
    245         my $task_queue    = Padre::SlaveDriver->new->task_queue; 
    246         my $worker_thread = threads->create( \&_worker_loop, $task_queue ); 
    247         $outqueue->enqueue( $worker_thread->tid ); 
     245        my $queue  = Padre::SlaveDriver->new->task_queue; 
     246        my $worker = threads->create( \&_worker_loop, $queue ); 
     247        $out->enqueue( $worker->tid ); 
    248248    } 
    249249 
  • trunk/Padre/lib/Padre/Startup.pm

    r11059 r11064  
    9999            } 
    100100            foreach my $file (@ARGV) { 
     101                require File::Spec; 
    101102                my $path = File::Spec->rel2abs($file); 
    102103                $socket->print("open $path\n"); 
     
    106107            return 0; 
    107108        } 
     109    } 
     110 
     111    # NOTE: Replace the following with if ( 0 ) will disable the 
     112    # slave master quick-spawn optimisation. 
     113 
     114    # If we are going to use threading, spawn off the slave 
     115    # driver as early as we possibly can so we reduce the amount of 
     116    # wasted memory copying to a minimum. 
     117    if ( $setting{threads} ) { 
     118        require Padre::SlaveDriver; 
     119        Padre::SlaveDriver->new; 
    108120    } 
    109121 
     
    162174    } 
    163175 
    164     # If we are going to use threading, spawn off the slave 
    165     # driver as early as we possibly can so we reduce the amount of 
    166     # wasted memory copying to a minimum. 
    167     if ( $setting{threads} and 0 ) { 
    168         require Padre::SlaveDriver; 
    169         Padre::SlaveDriver->new; 
    170     } 
    171  
    172176    return 1; 
    173177} 
  • trunk/Padre/lib/Padre/Wx/App.pm

    r10997 r11064  
    3131use strict; 
    3232use warnings; 
    33 use Carp (); 
    34 use Params::Util qw{ _INSTANCE }; 
     33use Carp      (); 
    3534use Padre::Wx (); 
    3635 
     
    4544# Constructor and Accessors 
    4645 
    47 sub new { 
    48     my $class = shift; 
    49     my $ide   = shift; 
    50     unless ( _INSTANCE( $ide, 'Padre' ) ) { 
    51         Carp::croak("Did not provide the ide object to Padre::App->new"); 
     46sub create { 
     47    my $self = shift->new; 
     48 
     49    # Check IDE param 
     50    my $ide = shift; 
     51    require Params::Util; 
     52    unless ( Params::Util::_INSTANCE($ide, 'Padre') ) { 
     53        Carp::croak("Did not provide the ide object to Padre::App->create"); 
    5254    } 
    53  
    54     # Create the Wx object 
    55     my $self = $class->SUPER::new; 
    5655 
    5756    # Save a link back to the parent ide 
Note: See TracChangeset for help on using the changeset viewer.