← All bug reports

FS#1305Bottleneck in DL_Dxf::toReal caused by std::locale

Type
Performance Issue
Status
Closed
Resolution
Implemented
Category
dxflib
Severity
Low
Priority
Low
Reported version
3.12.1
Operating system
All
Reported
2015-11-20 by mzeilfelder
Closed
2015-12-15 by andrew

Loading any larger dxf file takes very long because of this line:
istr.imbue(std::locale("C"));

The call to std::locale is very slow. File-loading can be speed up by approximately factor 5 times on my system when replacing it. I just removed that line and instead added the following in DL_Dxf::in so it is changed only once per file:

std::locale oldLocale = std::locale::global(std::locale("C")); // use dot in numbers
while (readDxfGroups(fp, creationInterface)) {}
std::locale::global(oldLocale);

Comments (2)

andrew 2015-11-20

Thanks for your suggestion.

Needs serious testing on several platforms. Note that an error in this part has very bad consequences (slightly wrong, rounded coordinates when loading DXF files).

mzeilfelder 2015-11-27

Conversion still uses the same locale, just once instead of every time. There isn't another call in the lib to set the locale so far, so shouldn't be reset in between. Some risk if people use it in a thread while changing the locale in another thread at the same time I guess. And maybe some risk in case you have other functions in loading which depend on the locale. Like for example if you create strings somewhere which should use the users locale instead.

But definitely worth it for speed. I'm currently evaluating the lib and it makes a lot of difference in development since I no longer have to wait > 10 seconds each time I load my test-models :-)

Btw, I used the tool "Very sleepy" to find this, highly recommended in case you haven't run into it yet!