← Back to team overview

kicad-developers team mailing list archive

Re: slow PCB_IO::Save()

 

On 10/24/2012 03:50 PM, Wayne Stambaugh wrote:
> On 10/24/2012 3:01 PM, Dick Hollenbeck wrote:
>> Wayne,
>>
>> I am seeing very slow operation of said function even in Release build mode.
>> Its bad enoughto warrant some study, maybe we can find a bottle neck.
>> We might need to run some performance analyzer on it find out where the time is going.
>>
>> Please test with the biggest board you can find.
>>
>> Thanks for any help you can offer on this,
>>
>> Dick
>>
> Dick,
>
> I wonder if this has anything to do with the fact that I used 
> wxFileOutputStream instead of wxFFile.  It's possible the overhead of 
> the output stream is causing the performance problems but you wouldn't 
> think so.  


Yep, that was it.  I wrote new class FILE_OUTPUTFORMATTER and it is  10 times faster than
STREAM_OUTFORMATTER for file streams.  STREAM_OUTPUTFORMATTER is now far less useful,
perhaps only for writing to a zip file or socket, or something purely academic that will
never happen.


Inside the virtual write() overload, it simply calls fwrite() which does the newline
translation if the file is on windows and opened in text mode.

Consider this now fixed.  Thanks for the idea, although I did not use wxFFile, simply
FILE*.   (No need to trust wx for the basics, as we've just seen.)


Dick


/**
 * Class FILE_OUTPUTFORMATTER
 * may be used for text file output.  It is about 8 times faster than
 * STREAM_OUTPUTFORMATTER for file streams.
 */
class FILE_OUTPUTFORMATTER : public OUTPUTFORMATTER
{
    FILE*   m_fp;           ///< takes ownership

public:
    FILE_OUTPUTFORMATTER( FILE* fp ) :
        m_fp( fp )
    {
    }

    ~FILE_OUTPUTFORMATTER()
    {
        if( m_fp )
            fclose( m_fp );
    }

protected:
    //-----<OUTPUTFORMATTER>------------------------------------------------
    void write( const char* aOutBuf, int aCount ) throw( IO_ERROR )
    {
        fwrite( aOutBuf, aCount, 1, m_fp );
    }
    //-----</OUTPUTFORMATTER>-----------------------------------------------
};


Follow ups

References