[fortran-dev, patch] Parsed format data caching

Jerry DeLisle jvdelisle@verizon.net
Sun Mar 29 01:20:00 GMT 2009


Jerry DeLisle wrote:
> Hi folks,
> 
> This patch uses the simplest of hashing functions to hash a format 
> string and save a pointer to the parsed format data and its tokenized 
> fnode tree.
> 
> This saves repeated re-parsing of format strings for every instance of a 
> formatted I/O operation, especially inside loops.
> 
> The method is probabilistic, meaning it relies on a good chance you 
> won't clobber previously saved data.  If there is a collision, the 
> previously saved data is discarded and replaced by the new.  The hash 
> table size is fixed with 16 entries.
> 
> On some test cases I have seen about 18% speed up in formatted I/O.
> 
> Regression tested on x86-64-linux-gnu.
> 
> OK for commit to fortran-dev branch?  If anyone is curious, the patch 
> will apply on 4.4 and 4.5 with some fuzz.
> 
> Regards,
> 
> Jerry
> 
ChangeLog I forgot:

2009-03-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

         PR libfortran/37754
	* io/io.h (format_hash_entry): New structure for hash table.
	(format_hash_table): The hash table itself.
	(free_format_data): Revise function prototype.
	(free_format_hash_table, init_format_hash,
	free_format_hash): New function prototypes.
	* io/unit.c (close_unit_1): Use free_format_hash_table.
	* io/transfer.c (st_read_done, st_write_done): Free format data if
	internal unit.
	* io/format.c (free_format_hash_table): New function that frees any
	memory allocated previously for cached format data.
	(reset_node): New static helper function to reset the format counters
	for a format node.
	(reset_fnode_counters): New static function recursively calls reset_node
	to traverse the	fnode tree.
	(format_hash): New simple hash function based on XOR, probabalistic,
	tosses collisions.
	(save_parsed_format): New static function to save the parsed format
	data to use again.
	(find_parsed_format): New static function searches the hash table
	looking for a match.
	(free_format_data): Revised to accept pointer to format data rather than
	the dtp pointer so that the function can be used in more places.
	(format_lex): Editorial.
	(parse_format_list): Set flag used to determine of format data hashing
	is to be used.  Internal units are not persistent enough for this.
	(revert): Move to ne location in file.
	(parse_format): Use new functions to look for previously parsed
	format strings and use them rather than re-parse.  If not found, saves
	the parsed format data for later use.



More information about the Fortran mailing list