<div dir="ltr">We are writing a raster importer, and finding that GDALRasterBand::RasterIO() is unexpectedly slow for some GRIB2 files.<div><br></div><div>We have a file which is about 1800x1000 pixels, with 49 bands of type DOUBLE. The file is about 47MB on disc.</div><div><br></div><div>Reading all the bands of a single scanline from this file takes about 1300ms, which is about 26ms per band, hence the entire file takes around 20 minutes to import. All the time seems to be spent in the RasterIO() call, even though it's not doing any raster rescaling or data format conversion (1:1 pixels, fetching as GDT_Float64).</div><div><br></div><div>So, I figured we'd try multi-threading it, but evidently the call is not thread-safe. Here is just one of various stack traces it will throw.</div><div><br></div><div>libc.so.6!raise (Unknown Source:0)<br>libc.so.6!abort (Unknown Source:0)<br>libc.so.6![Unknown/Just-In-Time compiled code] (Unknown Source:0)<br>libgdal.so.28!GRIBRasterBand::UncacheData(GRIBRasterBand * const this) (/build/scripts/gdal-3.2.2/frmts/grib/gribdataset.cpp:948)<br>libgdal.so.28!GRIBRasterBand::LoadData(GRIBRasterBand * const this) (/build/scripts/gdal-3.2.2/frmts/grib/gribdataset.cpp:730)<br>libgdal.so.28!GRIBRasterBand::LoadData(GRIBRasterBand * const this) (/build/scripts/gdal-3.2.2/frmts/grib/gribdataset.cpp:697)<br>libgdal.so.28!GRIBRasterBand::IReadBlock(GRIBRasterBand * const this, int nBlockYOff, void * pImage) (/build/scripts/gdal-3.2.2/frmts/grib/gribdataset.cpp:803)<br>libgdal.so.28!GDALRasterBand::GetLockedBlockRef(int bJustInitialize, int nYBlockOff, int nXBlockOff, GDALRasterBand * const this) (/build/scripts/gdal-3.2.2/gcore/gdal_priv.h:963)<br>libgdal.so.28!GDALRasterBand::GetLockedBlockRef(GDALRasterBand * const this, int nXBlockOff, int nYBlockOff, int bJustInitialize) (/build/scripts/gdal-3.2.2/gcore/gdalrasterband.cpp:1238)<br>libgdal.so.28!GDALRasterBand::IRasterIO(GDALRasterBand * const this, GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void * pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, GSpacing nPixelSpace, GSpacing nLineSpace, GDALRasterIOExtraArg * psExtraArg) (/build/scripts/gdal-3.2.2/gcore/rasterio.cpp:149)<br>libgdal.so.28!GDALRasterBand::RasterIO(GDALRasterBand * const this, GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void * pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, GSpacing nPixelSpace, GSpacing nLineSpace, GDALRasterIOExtraArg * psExtraArg) (/build/scripts/gdal-3.2.2/gcore/gdalrasterband.cpp:372)<br>import_export::Importer::<lambda(size_t, int)>::operator()(size_t, int) const(const import_export::Importer::<lambda(size_t, int)> * const __closure, const size_t thread_id, const int y) (/home/simon.eves/work/omniscidb-internal/ImportExport/Importer.cpp:5721)<br></div><div>...</div><div><br></div><div>All of the parameters to the call are either constant or uncontended simple variables, and obviously there is a unique data buffer (pData) per thread.</div><div><br></div><div>Is there anything we can do to make this work?</div><div><br></div><div>I was intending to look into the lower level block-based API, in the hope that it will be faster, but have not yet done so.</div><div><br></div><div>This is all with a local static build of GDAL 3.2.2 on Ubuntu 20.04 with GCC 9.<br></div><div><div><br></div><div>Yours,</div><div><br></div><div>Simon Eves</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="margin:0px;padding:0px 0px 20px;width:2544px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:medium"><div><div style="font-size:12.8px;margin:8px 0px 0px;padding:0px"><div><div dir="ltr"><span><font color="#888888"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><table cellpadding="0" cellspacing="0" border="0" style="font-family:Times;width:2544px"><tbody><tr><td align="left" style="vertical-align:top;font-size:0px"><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td align="left" style="padding:0px 15px 0px 0px;vertical-align:middle"><font face="arial, helvetica, sans-serif" size="2"><a href="http://www.omnisci.com/" target="_blank"><img src="http://www2.omnisci.com/l/298412/2018-09-18/3sqpg/298412/61753/OmniSci_Email_Header2.png"></a><br></font></td><td align="left" style="padding:0px 0px 0px 15px;vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="width:215px"><tbody><tr><td align="left" style="vertical-align:top"><span style="white-space:nowrap;color:rgb(0,0,1)"><span style="color:rgb(14,76,144);font-weight:700"><font face="arial, helvetica, sans-serif" size="2">Simon Eves</font></span></span></td></tr><tr><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td align="left" style="vertical-align:top"><span style="white-space:nowrap;color:rgb(0,0,1)"><font face="arial, helvetica, sans-serif" size="2">Senior Graphics Engineer, Rendering Group<br>100 Montgomery St (5th Floor), San Francisco, CA 94104, USA<br></font></span></td></tr></tbody></table></td></tr><tr><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td align="left" style="padding:0px;vertical-align:top"><br></td><td align="left" style="padding:0px;vertical-align:top"><br></td></tr><tr><td align="left" style="padding:0px;vertical-align:top"><span style="white-space:nowrap;color:rgb(0,0,1)"><font face="arial, helvetica, sans-serif" size="2">Email: <a href="mailto:simon.eves@omnisci.com" target="_blank">simon.eves@omnisci.com</a> | Cell: </font></span></td><td align="left" style="padding:0px;vertical-align:top"><span style="white-space:nowrap;color:rgb(0,0,1)"><font face="arial, helvetica, sans-serif" size="2">+1 (415) 902-1996</font></span></td></tr></tbody></table><br></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table><br></div></div></div></div></div></div></div></div></div></div></font></span></div><div></div></div></div><div></div></div></div></div></div></div></div></div></div></div></div></div></div>