setUsingMemoryCache(True) helps QGIS avoid repeating the HTTP round-trip for every single feature, but it still has to download every feature of the join layer once, keep it in RAM and then run the match in Python.
If the WFS layer is large (many features / many attributes) the download + in-memory search quickly becomes the bottleneck.
Below is a checklist of tactics that usually give the biggest speed-ups, roughly ordered from “quick fixes” to “infrastructure changes”.
QGIS’ join algorithm tries to use a provider-side attribute index if one exists.
For file-based layers (GeoPackage, Shapefile, …) you can create it like:
(Unfortunately, most WFS servers do not expose attribute indices, which is another reason local copies are usually faster.)
3 Join only the columns you really need
python
ji = QgsVectorLayerJoinInfo()
ji.setJoinLayer(join_layer)
ji.setJoinFieldName('key')
ji.setTargetFieldName('key')
ji.setUsingMemoryCache(True) # you already have this
ji.setJoinFieldNamesSubset(['name', 'population'])
target_layer.addJoin(ji)
If you omit setJoinFieldNamesSubset QGIS will copy every attribute, bloating memory usage and slowing the copy step.
4 Turn the WFS layer into a local layer before joining
The biggest performance leap usually comes from eliminating the network:
python
tmp = '/tmp/join.gpkg'
# Download once
QgsVectorFileWriter.writeAsVectorFormat(
join_layer, tmp, 'utf-8', join_layer.crs(), 'GPKG'
)
# Re-load the local copy and create index
local_join = QgsVectorLayer(tmp + "|layername=join", 'join_local', 'ogr')
prov = local_join.dataProvider()
prov.createAttributeIndex(local_join.fields().indexOf('key'))
# Now build the join against the local layer
If the layer updates only once a day (or week), automate that download in a nightly cron job and keep working against the fast GeoPackage/PostGIS copy during the day.
5 Use a virtual layer / SQL join instead of QgsVectorLayerJoinInfo
Virtual layers leverage SQLite + GDAL and are surprisingly fast:
python
sql = """
SELECT
t.*,
j.population, -- only needed columns
j.name
FROM target_layer t
LEFT JOIN join_local j
ON t.key = j.key
"""
vl = QgsVectorLayer(f"?query={sql}", "virtual_join", "virtual")
QgsProject.instance().addMapLayer(vl)
Because both layers are already local (OGR / GeoPackage), SQLite can run an indexed join in C++ instead of Python, giving orders-of-magnitude speed-ups.
6 Push the join to a real database (PostGIS, SpatiaLite)
For very large datasets (hundreds of thousands to millions of features) nothing beats a database with proper B-tree or GiST indexes:
ogr2ogr -f PostgreSQL ... or QGIS ➜ Database ➜ DB Manager ➜ Import…
CREATE INDEX ON join_table(key);
Use a single SQL layer in QGIS that already contains the joined view.
QGIS only renders what you see; the database does the heavy lifting.
7 Miscellaneous small wins
• Keep both layers in the same CRS – avoids on-the-fly reprojection during the join.
• Make sure the join key is an integer or short text; long strings are slower to compare.
• Use the latest QGIS / GDAL. Many optimisations (especially around WFS 2.0 paging) landed in QGIS 3.28+.
TL;DR
setUsingMemoryCache(True) is fine for a couple of thousand features, but if your WFS layer is 50 k, 500 k, or more, the real fix is:
Download it once to GeoPackage / PostGIS.
Index the join column.
Either do the join with a virtual layer or let the database handle it.
That single change usually turns multi-minute joins into sub-second operations.