Created attachment 860 [details] G4LogicalSkinSurface.patch, modifies source/geometry/volumes/include/G4LogicalSkinSurface.hh, source/geometry/volumes/src/G4LogicalSkinSurface.cc, source/persistency/gdml/src/G4GDMLWriteStructure.cc We (Electron-Ion Collider) have a geometry where two features in separate detectors are 'conspiring' to result in poor performance. This both concerns optical photon propagation in Cherenkov detectors. - In our Dual RICH detector with O(20) optical photons per event, reflections on the SiPM surfaces is important, so we model this with a skin surface for each SiPM, so O(1000). - In our DIRC detector with O(2000) optical photons per event, each photon undergoes frequent O(100) total internal reflections, but there are only O(10) skin surfaces in this detector itself. We noticed a slowdown in our simulations only when both these detectors are simultaneously included, but not when only one is included. We tracked this down to G4LogicalSkinSurface::GetSurface where a linear search is done over the global vector with all skin surfaces everywhere. This makes sense that the large number of skin surfaces in the vector would take a long time to traverse, and we would be calling this function frequently due to sheer number of photons. Indeed, in the attached patch we change the vector storage model for skin surface to a map storage model (as is already the case for G4LogicalBorderSurface). This allows the use of a faster std::map::find which performs in O(log n) (instead of O(n) previously).
Thanks for suggested correction. This is now submitted in the development branch and will part of the next release/patch!