Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/Core VCL    [ Add a report in this area ]  
Report #:  75575   Status: Open
Suggestion to improve TDataset.FindByName performance
Project:  Delphi Build #:  21218
Version:    12.1 Submitted By:   Mason Wheeler
Report Type:  Suggestion / Enhancement Request Date Reported:  7/6/2009 5:30:56 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   278628
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
TDataset.FindByName is well-known for its slow performance, especially in loops.  Every time it's called, it runs a (slow) linear search, doing a (slow) string comparison against every field name until it finds a match.  It's bad enough that it's become a common design pattern to preallocate local TField variables in functions that have to use FindByName, so the call will only have to be made once for each field.

This overhead could be alleviated quite a bit by replacing the linear search with a hashtable lookup.  Add a TDictionary<string, TField> to TFields, and have TFields.FindField check it.  Make sure to uppercase all the strings first, to preserve case insensitivity.

Suddenly instead of a slow string comparison multiplied by a slow O(N) search, we have a slow string-hashing operation multiplied by a much faster O(1) search.
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01