Getting flag for the column via helper method #492

Merged
nemec784 merged 2 commits from impr/column_flag into master 2016-11-12 03:30:16 +00:00
nemec784 commented 2016-11-11 17:22:45 +00:00 (Migrated from github.com)

Columns in the maps (such as statement.columnMap, statement.mustColumnMap, statement.nullableMap) are placed in lowercase.

Each time, when there is need to get any flag from map, name of the column converts to lowercase. Every calling of strings.ToLower makes new allocations.

As an example - all columns in function statement.buildCondsare checking via statement.mustColumnMap (which is filled up only for update statements). This operation makes 2*columns_count unnecessary allocations.

Simple way to fix it - is to make helper method for flag getting from the map via case insensitive keys comparison.

Benchmarks of the current realization and offered way above (simple flag getting from the map, 9 columns):

BenchmarkGetFlagForColumnWithToLower_ContainsKey-4   	 1000000	      1911 ns/op	     144 B/op	      18 allocs/op
BenchmarkGetFlagForColumnWithToLower_EmptyMap-4      	 1000000	      1661 ns/op	     144 B/op	      18 allocs/op

BenchmarkGetFlagForColumnWithICKey_ContainsKey-4     	 1000000	      1935 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetFlagForColumnWithICKey_EmptyMap-4        	50000000	        40.8 ns/op	       0 B/op	       0 allocs/op
Columns in the maps (such as `statement.columnMap`, `statement.mustColumnMap`, `statement.nullableMap`) are placed in lowercase. Each time, when there is need to get any flag from map, name of the column converts to lowercase. Every calling of `strings.ToLower` makes new allocations. As an example - all columns in function `statement.buildConds`are checking via `statement.mustColumnMap` (which is filled up only for update statements). This operation makes 2*columns_count unnecessary allocations. Simple way to fix it - is to make helper method for flag getting from the map via case insensitive keys comparison. Benchmarks of the current realization and offered way above (simple flag getting from the map, 9 columns): ``` BenchmarkGetFlagForColumnWithToLower_ContainsKey-4 1000000 1911 ns/op 144 B/op 18 allocs/op BenchmarkGetFlagForColumnWithToLower_EmptyMap-4 1000000 1661 ns/op 144 B/op 18 allocs/op BenchmarkGetFlagForColumnWithICKey_ContainsKey-4 1000000 1935 ns/op 0 B/op 0 allocs/op BenchmarkGetFlagForColumnWithICKey_EmptyMap-4 50000000 40.8 ns/op 0 B/op 0 allocs/op ```
Sign in to join this conversation.
No description provided.