-
Notifications
You must be signed in to change notification settings - Fork 45
Improve Performance #4
Comments
Probably there are ways to optimize this, but I didn't design this library with perf as a top priority. I'll keep this issue open to remind me to investigate - but feel free to send a PR if you figure out a better approach! 😄 |
I've been discussing this offline with another developer (who will hopefully chime in here), who thinks better perf can be obtained by using inline table-valued functions instead of scalar-valued functions. I'm looking forward to his PR. |
FYI, I am working on performance improvements, but also (and sorry I didn't notice this earlier @sargurgn) - timestamps are rarely kept in numeric format unless they are in UTC. The idea of a number of milliseconds since 1970-01-01 local time is not a good one. I recommend against that. If you need local time, keep it in a |
@mj1856 you want to switch to inline functions, and you want to schema bind. Both should get you some serious boost on performance, as the query optimizer can interpret them significantly better. Since I'm going to use this in my own code, I'll see if I can't deal with this this week. I have some reports that are going to call your functions on millions of rows, so if they suck I'll find out :-) |
@mj1856 , @maggiepint , and sargurgn : As it relates to performance improvements, I have mocked up (and tested) new versions of GetZoneId and UtcToLocal (was going to do LocalToUtc later if this worked out well). I am not sure of the best way to show them. I did not want to update the existing functions as I changed them both to be Inline TVFs, hence there is no possibility backwards compatibility if I were to replace the definitions of the same function names. And, I did not know how you wanted to handle naming convention, and I have very little time to work on this in the first place but wanted to help. So, for now, hopefully it is ok for me to post the code here that can be run in a Database containing this project (since the new functions are unique object names). I also included the simple performance tests and they show improvements on both functions. If I should do a pull request instead I can do that and perhaps someone can make changes to naming convention, etc? Either way, here is what I have: CODE
TESTS
|
Hi,
My table has 2 million records. Your
UtcToLocal
function takes around 120 seconds to fetch the converted records. Any help to optimize this would be great help. Thanks in advance.My table structure:
I have created the following function, for the conversion
I am accessing this way,
If i replace your
Tzdb.UtcToLocal
function withSWITCHOFFSET
it takes not more than 4 secs for 2 million records. I see that there are 3 queries in the function which fetches the zoneId and offset. Any ways to optimize this?The text was updated successfully, but these errors were encountered: