TValueHelper.TryConvert is extrimely slow on Linux platform

Issue #302 resolved
Leonid Huber created an issue

I use ORM to load data from PostgrseSQL server. The mapping process from recordset to entity is extrimely slow on Linux platform because TValueHelper.TryConvert method creates the formatSettings record every time whenever this method is called. The reason is that call of TFormatSettings.Create method is very slow on Linux platform. Please pay attention to this issue.

Comments (11)

  1. Stefan Glienke repo owner
    • changed status to open

    What exactly makes it slow on Linux? Is it worth reporting that to Embarcadero?

    As for your proposed change this possibly breaks code when region settings are changed while the application is running which is why I hesitate to accept this.

  2. Former user Account Deleted

    @Leonid Huber How much "extremely slow"? what are the numbers to compare?

    For Linux Servers in production, after configuring the server, changing the region configuration is not a common practice, and if it is really needed, restarting the server is the safest option or at least the application.

    As for Windows apps, it can happen at any time.

    Maybe a TValueHelper.TryConvert overload with a TFormatSettings param can help on this issue on Linux Server apps, so the developer can decide to create and manage the TFormatSettings for performance purpose.

  3. Stefan Glienke repo owner

    Well, after looking into the Delphi source code it seems that only the VCL takes care of a change to these settings in TApplication.CheckIniChange where it calls GetFormatSettings so will consider not calling TFormatSettings.Create every time but cache it but offer a public method to update it if necessary.

  4. Stefan Glienke repo owner

    @cesarhbsis There is an overload to pass your own TFormatSettings but the one without that parameter is being used inside the ORM. Now the ORM could certainly have its own TFormatSettings instance and pass it but I fear this would require passing that instance through several layers of the ORM depending on where it is needed as I don't know that right now.

    Anyway regardless of what OS not having to call TFormatSettings.Create every time would certainly be better anyway.

  5. Leonid Huber reporter

    Ok, I've just compared how long simple operation "TFormatSettings.Create" performed 400 times. On Windows 10 platform it takes 3ms, on Linux 457ms. Then I've tried to load 200 records from DB on Windows 10 platform, it took less then 240ms, on Linux platform it took more then 7120ms. When I have changed Spring.pas in such way that TFormatSettings.Create started to be called only once when the module is initialized and used the same formatSettings only once initialized variable every time whenever TValueHelper.TryConvert called, the performance of entity mapping procedure had become appropriate, without long delay...

  6. Stefan Glienke repo owner

    @lhuber72 I can reproduce these results and after some reading through the code for Linux that gets executed and making some improvements in places I suspected to be the main cause of such slow down (no, they were not) I think that TryConvert should be changed - I just have not decided how exactly.

  7. Log in to comment