← Back to team overview

kicad-developers team mailing list archive

[PATCH] - Improve symbol library load speed

 

Attached is a patch that provides a ~90% reduction in the time taken to
load symbol libraries when launching eeschema.

Test case: Add all available libraries on my system to the search path.
Prior to this patch, 40 seconds to load libraries. Now, 4 seconds!

Essentially, each pin was being tested against every other pin in the
symbol, multiple times. Each test required a vector to be created and then
destroyed.

Now these comparisons can be ignored, and (I think?) this makes sense at
initial load.

Cheers,

Oliver
From 76255bcaf9f4022bbc680a9b12b94da4e89455a5 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@xxxxxxxxx>
Date: Thu, 28 Sep 2017 19:47:02 +1000
Subject: [PATCH] Added option to not test other pins when setting pin
 parameters

- On loading from file, other pins are not LINKED and thus can be ignored
- 90% reduction in library load time when launching eeschema
---
 eeschema/lib_pin.cpp           | 30 ++++++++++++++++++++++++------
 eeschema/lib_pin.h             | 18 ++++++++++++------
 eeschema/sch_legacy_plugin.cpp | 32 ++++++++++++++++----------------
 3 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index 786181f..1f99840 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -156,7 +156,7 @@ LIB_PIN::LIB_PIN( LIB_PART*      aParent ) :
 }
 
 
-void LIB_PIN::SetName( const wxString& aName )
+void LIB_PIN::SetName( const wxString& aName, bool aTestOtherPins )
 {
     wxString tmp = ( aName.IsEmpty() ) ? wxT( "~" ) : aName;
 
@@ -168,6 +168,9 @@ void LIB_PIN::SetName( const wxString& aName )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
@@ -185,7 +188,7 @@ void LIB_PIN::SetName( const wxString& aName )
 }
 
 
-void LIB_PIN::SetNameTextSize( int size )
+void LIB_PIN::SetNameTextSize( int size, bool aTestOtherPins )
 {
     if( size != m_nameTextSize )
     {
@@ -193,6 +196,9 @@ void LIB_PIN::SetNameTextSize( int size )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
@@ -210,7 +216,7 @@ void LIB_PIN::SetNameTextSize( int size )
 }
 
 
-void LIB_PIN::SetNumberTextSize( int size )
+void LIB_PIN::SetNumberTextSize( int size, bool aTestOtherPins )
 {
     if( size != m_numTextSize )
     {
@@ -218,6 +224,9 @@ void LIB_PIN::SetNumberTextSize( int size )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
@@ -235,7 +244,7 @@ void LIB_PIN::SetNumberTextSize( int size )
 }
 
 
-void LIB_PIN::SetOrientation( int orientation )
+void LIB_PIN::SetOrientation( int orientation, bool aTestOtherPins )
 {
     if( m_orientation != orientation )
     {
@@ -243,6 +252,9 @@ void LIB_PIN::SetOrientation( int orientation )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
@@ -290,7 +302,7 @@ void LIB_PIN::SetShape( GRAPHIC_PINSHAPE aShape )
 }
 
 
-void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType )
+void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins )
 {
     assert( aType >= 0 && aType < (int)PINTYPE_COUNT );
 
@@ -306,6 +318,9 @@ void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
@@ -323,7 +338,7 @@ void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType )
 }
 
 
-void LIB_PIN::SetLength( int length )
+void LIB_PIN::SetLength( int length, bool aTestOtherPins )
 {
     if( m_length != length )
     {
@@ -331,6 +346,9 @@ void LIB_PIN::SetLength( int length )
         SetModified();
     }
 
+    if( !aTestOtherPins )
+        return;
+
     if( GetParent() == NULL )
         return;
 
diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h
index ff8b9a2..2999365 100644
--- a/eeschema/lib_pin.h
+++ b/eeschema/lib_pin.h
@@ -170,8 +170,9 @@ public:
      * This will also all of the pin names marked by EnableEditMode().
      *
      * @param aName New pin name.
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetName( const wxString& aName );
+    void SetName( const wxString& aName, bool aTestOtherPins = true );
 
     /**
      * Set the \a aSize of the pin name text.
@@ -180,8 +181,9 @@ public:
      * by EnableEditMode().
      *
      * @param aSize The text size of the pin name in schematic units ( mils ).
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetNameTextSize( int aSize );
+    void SetNameTextSize( int aSize, bool aTestOtherPins = true );
 
     int GetNameTextSize() const { return m_nameTextSize; }
 
@@ -209,8 +211,9 @@ public:
      * by EnableEditMode().
      *
      * @param aSize The text size of the pin number in schematic units ( mils ).
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetNumberTextSize( int aSize );
+    void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
 
     int GetNumberTextSize() const { return m_numTextSize; }
 
@@ -222,8 +225,9 @@ public:
      * This will also update the orientation of the pins marked by EnableEditMode().
      *
      * @param aOrientation - The orientation of the pin.
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetOrientation( int aOrientation );
+    void SetOrientation( int aOrientation, bool aTestOtherPins = true );
 
     void Rotate() override;
 
@@ -279,8 +283,9 @@ public:
      * EnableEditMode().
      *
      * @param aType - The electrical type of the pin(see enun ELECTRICAL_PINTYPE for values).
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetType( ELECTRICAL_PINTYPE aType );
+    void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
 
     /**
      * Set the pin length.
@@ -288,8 +293,9 @@ public:
      * This will also update the length of the pins marked by EnableEditMode().
      *
      * @param aLength - The length of the pin in mils.
+     * @param aTestOtherPins determines if other pins need to be updated
      */
-    void SetLength( int aLength );
+    void SetLength( int aLength, bool aTestOtherPins = true );
 
     int GetLength() { return m_length; }
 
diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp
index 5b31658..c73dad3 100644
--- a/eeschema/sch_legacy_plugin.cpp
+++ b/eeschema/sch_legacy_plugin.cpp
@@ -3026,7 +3026,7 @@ LIB_PIN* SCH_LEGACY_PLUGIN_CACHE::loadPin( std::unique_ptr< LIB_PART >& aPart,
     parseUnquotedString( name, aReader, line, &line );
     parseUnquotedString( number, aReader, line, &line );
 
-    pin->SetName( name );
+    pin->SetName( name, false );
     pin->SetNumber( number );
 
     wxPoint pos;
@@ -3034,10 +3034,10 @@ LIB_PIN* SCH_LEGACY_PLUGIN_CACHE::loadPin( std::unique_ptr< LIB_PART >& aPart,
     pos.x = parseInt( aReader, line, &line );
     pos.y = parseInt( aReader, line, &line );
     pin->SetPosition( pos );
-    pin->SetLength( parseInt( aReader, line, &line ) );
-    pin->SetOrientation( parseChar( aReader, line, &line ) );
-    pin->SetNumberTextSize( parseInt( aReader, line, &line ) );
-    pin->SetNameTextSize( parseInt( aReader, line, &line ) );
+    pin->SetLength( parseInt( aReader, line, &line ), false );
+    pin->SetOrientation( parseChar( aReader, line, &line ), false );
+    pin->SetNumberTextSize( parseInt( aReader, line, &line ), false );
+    pin->SetNameTextSize( parseInt( aReader, line, &line ), false );
     pin->SetUnit( parseInt( aReader, line, &line ) );
     pin->SetConvert( parseInt( aReader, line, &line ) );
 
@@ -3051,47 +3051,47 @@ LIB_PIN* SCH_LEGACY_PLUGIN_CACHE::loadPin( std::unique_ptr< LIB_PART >& aPart,
     switch( type )
     {
     case 'I':
-        pin->SetType( PIN_INPUT );
+        pin->SetType( PIN_INPUT, false );
         break;
 
     case 'O':
-        pin->SetType( PIN_OUTPUT );
+        pin->SetType( PIN_OUTPUT, false );
         break;
 
     case 'B':
-        pin->SetType( PIN_BIDI );
+        pin->SetType( PIN_BIDI, false );
         break;
 
     case 'T':
-        pin->SetType( PIN_TRISTATE );
+        pin->SetType( PIN_TRISTATE, false );
         break;
 
     case 'P':
-        pin->SetType( PIN_PASSIVE );
+        pin->SetType( PIN_PASSIVE, false );
         break;
 
     case 'U':
-        pin->SetType( PIN_UNSPECIFIED );
+        pin->SetType( PIN_UNSPECIFIED, false );
         break;
 
     case 'W':
-        pin->SetType( PIN_POWER_IN );
+        pin->SetType( PIN_POWER_IN, false );
         break;
 
     case 'w':
-        pin->SetType( PIN_POWER_OUT );
+        pin->SetType( PIN_POWER_OUT, false );
         break;
 
     case 'C':
-        pin->SetType( PIN_OPENCOLLECTOR );
+        pin->SetType( PIN_OPENCOLLECTOR, false );
         break;
 
     case 'E':
-        pin->SetType( PIN_OPENEMITTER );
+        pin->SetType( PIN_OPENEMITTER, false );
         break;
 
     case 'N':
-        pin->SetType( PIN_NC );
+        pin->SetType( PIN_NC, false );
         break;
 
     default:
-- 
2.7.4


Follow ups