[QGIS-Developer] Difference between QgsVectorFileWriter and QgsOgrProvider when creating gpkg?

Nyall Dawson nyall.dawson at gmail.com
Fri Oct 16 22:21:24 PDT 2020

Hi list,

After watching Tim's recent screencast where extracting nodes to a
geopackage took forever, I've tracked down a strange thing, which I
can't explain!

We have two different ways of creating a Geopackage in QGIS:

1. Via QgsVectorFileWriter, which is the generic class for creation of
disk based vector files
2. Via QgsVectorLayerExporter, which uses the standard vector data
providers to allow creation of new layers for any provider. (Used by
Processing in the screencast when Tim selected the "save to
geopackage" option)

That's fine, both classes exist for a reason.

But I've just discovered that using QgsVectorFileWriter to save a
layer to a GPKG is MUCH MUCH faster than QgsVectorLayerExporter, and
I'm at a loss to explain why.

The main difference I see when profiling comes down to the speed of
the call to OGRGeoPackageTableLayer::ICreateFeature.

Via QgsVectorLayerExporter, I can see that the sqllite3_step call used
by ICreateFeature spends a huge amount of time in rtreeUpdate. I don't
see ANY call to rtreeUpdate from the sqlite3_step call made by
ICreateFeature when QgsVectorFileWriter is used to create the

But I can't explain this. In both cases the resultant gpkg has a
spatial index. Does anyone know why one of the methods is so much
slower than the other? (And ultimately, can we fix
QgsVectorLayerExporter so it uses the same fast approach!)


More information about the QGIS-Developer mailing list