title: How to optimize filtering of a layer in QGS API
body: <p>I'm developping a QGIS plugin (under version 2.8.1) for traffic assignment where I want to show the results of my simulation at each time step. Right now I'm using Time Manager plugin but it gets very slow when my layer has hundreds of thousands of attributes. In my case I know exactly what feature IDs I want to show at each time step so I thought it would be easy to make it faster. </p>
  
  <p>Here is what I tried (sorry of my way of python programming but I'm quite new using this language): at each time step of my loop I set the ordered list of     indexes of attributes to show (they are always ordered in my case).</p>
  
  <pre><code># TEST 1 -----------------------------------
  for step in time_steps:
              index_start = my_list_of_indexes_start[step]
              index_end = my_list_of_indexes_end[step]
              expression = 'fid &gt;= ' + str(index_start) + ' AND fid &lt;= ' + str(index_end)
              # Or for optimization tests
              # expression = '"FIELD_TIME"' + "=" + str(step)
              layer_dynamic.setSubsetString(expression)
              self.iface.mapCanvas().refresh()                
              time.sleep(0.2)
  # TEST 2 ------------------------------------
  for step in time_steps:
              index_start = my_list_of_indexes_start[step]
              index_end = my_list_of_indexes_end[step]
              indexes = list(j for j in range(index_start, index_end))
              request = QgsFeatureRequest().setFilterFids(indexes)
              layer_dynamic.getFeatures(request)
              self.iface.mapCanvas().refresh()                
              time.sleep(0.2)
  </code></pre>
  
  <p>Solution 1 with</p>
  
  <pre><code>layer_dynamic.setSubsetString(expression)
  </code></pre>
  
  <p>works as it refresh the view with the correct filtered features displayed on canvas at each time step but it is even slower than using a SQL expression not based on the indexes but on attributes values (as shown in comment in TEST 1 loop).</p>
  
  <p>Solution 2 with</p>
  
  <pre><code>layer_dynamic.getFeatures(request)
  </code></pre>
  
  <p>is fast but the display of the layer doesn't change.
  Any idea why?</p>