@@ -354,6 +354,28 @@ BiomeLayer::createImageImplementation(
354
354
}
355
355
}
356
356
357
+ // Make a small l2 cache of biomes that we've already looked up and search the vector
358
+ // before going to the catalog. This is a performance optimization to avoid repeated queries into a potentially large catalog.
359
+ std::vector< const Biome* > biomeCache;
360
+ auto getBiome = [&](const std::string& id) -> const Biome*
361
+ {
362
+ // Search the cache first
363
+ for (auto i : biomeCache)
364
+ {
365
+ if (i->id () == id)
366
+ {
367
+ return i;
368
+ }
369
+ }
370
+
371
+ auto result = getBiomeCatalog ()->getBiome (id);
372
+ if (result)
373
+ {
374
+ biomeCache.push_back (result);
375
+ }
376
+ return result;
377
+ };
378
+
357
379
iter.forEachPixelOnCenter ([&]()
358
380
{
359
381
const Biome* biome = nullptr ;
@@ -381,7 +403,7 @@ BiomeLayer::createImageImplementation(
381
403
{
382
404
if (sample->biomeid ().isSet ())
383
405
{
384
- biome = getBiomeCatalog ()-> getBiome (sample->biomeid ().get ());
406
+ biome = getBiome (sample->biomeid ().get ());
385
407
}
386
408
}
387
409
}
@@ -408,7 +430,7 @@ BiomeLayer::createImageImplementation(
408
430
// if the biomeid() is set, we are overriding the biome expressly:
409
431
if (sample->biomeid ().isSet ())
410
432
{
411
- biome = getBiomeCatalog ()-> getBiome (sample->biomeid ().get ());
433
+ biome = getBiome (sample->biomeid ().get ());
412
434
}
413
435
414
436
// If we have a biome, but there are traits set, we need to
@@ -422,7 +444,7 @@ BiomeLayer::createImageImplementation(
422
444
std::string implicit_biome_id =
423
445
biome->id () + " ." + AssetTraits::toString (sorted);
424
446
425
- const Biome* implicit_biome = getBiomeCatalog ()-> getBiome (implicit_biome_id);
447
+ const Biome* implicit_biome = getBiome (implicit_biome_id);
426
448
427
449
if (implicit_biome)
428
450
{
0 commit comments