Skip to content

Commit baf26fc

Browse files
author
Andi Kleen
committed
Size input line cache based on file size
While the input line cache size now tunable it's better if the compiler auto tunes it. Otherwise large files needing random file access will still have to search many lines to find the right lines. Add support for allocating one line anchor per hundred input lines. This means an overhead of ~235k per 1M input lines on 64bit, which seems reasonable. gcc/ChangeLog: PR preprocessor/118168 * input.cc (file_cache_slot::get_next_line): Implement dynamic sizing of m_line_record based on input length. * params.opt: (param_file_cache_lines): Set to 0 to size dynamically.
1 parent 33acec6 commit baf26fc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

gcc/input.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class file_cache_slot
189189

190190
};
191191

192-
size_t file_cache_slot::line_record_size = 100;
192+
size_t file_cache_slot::line_record_size = 0;
193193

194194
/* Tune file_cache. */
195195
void
@@ -856,8 +856,13 @@ file_cache_slot::get_next_line (char **line, ssize_t *line_len)
856856
size_t delta = rlen >= 1 ?
857857
m_line_num - m_line_record[rlen - 1].line_num : 1;
858858

859+
size_t max_size = line_record_size;
860+
/* One anchor per hundred input lines. */
861+
if (max_size == 0)
862+
max_size = m_line_num / 100;
863+
859864
/* If we're too far beyond drop half of the lines to rebalance. */
860-
if (rlen == line_record_size && delta >= spacing*2)
865+
if (rlen == max_size && delta >= spacing*2)
861866
{
862867
size_t j = 0;
863868
for (size_t i = 1; i < rlen; i += 2)
@@ -867,7 +872,7 @@ file_cache_slot::get_next_line (char **line, ssize_t *line_len)
867872
spacing *= 2;
868873
}
869874

870-
if (rlen < line_record_size && delta >= spacing)
875+
if (rlen < max_size && delta >= spacing)
871876
m_line_record.safe_push
872877
(file_cache_slot::line_info (m_line_num,
873878
m_line_start_idx,

gcc/params.opt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ Maximal estimated growth of function body caused by early inlining of single cal
136136

137137
-param=file-cache-files=
138138
Common Joined UInteger Var(param_file_cache_files) Init(16) Param
139-
Max number of files in the file cache.
139+
Max number of files in the file cache. When 0 this is automatically sized.
140140

141141
-param=file-cache-lines=
142-
Common Joined UInteger Var(param_file_cache_lines) Init(100) Param
142+
Common Joined UInteger Var(param_file_cache_lines) Init(0) Param
143143
Max number of lines to index into file cache.
144144

145145
-param=fsm-scale-path-stmts=

0 commit comments

Comments
 (0)