aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Kleen <ak@gcc.gnu.org>2024-12-26 13:05:57 -0800
committerAndi Kleen <ak@gcc.gnu.org>2025-02-02 21:59:22 -0800
commitbaf26fccfb51fa54fcf7c668b96cae4cdbe574b3 (patch)
tree4de5eea1809b7c13e618664ae880e26276e6f298
parent33acec612423efd2d9db9ffc808c4d103840dcd2 (diff)
downloadgcc-baf26fccfb51fa54fcf7c668b96cae4cdbe574b3.zip
gcc-baf26fccfb51fa54fcf7c668b96cae4cdbe574b3.tar.gz
gcc-baf26fccfb51fa54fcf7c668b96cae4cdbe574b3.tar.bz2
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.
-rw-r--r--gcc/input.cc11
-rw-r--r--gcc/params.opt4
2 files changed, 10 insertions, 5 deletions
diff --git a/gcc/input.cc b/gcc/input.cc
index 64cb85e..3416c7c 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -189,7 +189,7 @@ public:
};
-size_t file_cache_slot::line_record_size = 100;
+size_t file_cache_slot::line_record_size = 0;
/* Tune file_cache. */
void
@@ -856,8 +856,13 @@ file_cache_slot::get_next_line (char **line, ssize_t *line_len)
size_t delta = rlen >= 1 ?
m_line_num - m_line_record[rlen - 1].line_num : 1;
+ size_t max_size = line_record_size;
+ /* One anchor per hundred input lines. */
+ if (max_size == 0)
+ max_size = m_line_num / 100;
+
/* If we're too far beyond drop half of the lines to rebalance. */
- if (rlen == line_record_size && delta >= spacing*2)
+ if (rlen == max_size && delta >= spacing*2)
{
size_t j = 0;
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)
spacing *= 2;
}
- if (rlen < line_record_size && delta >= spacing)
+ if (rlen < max_size && delta >= spacing)
m_line_record.safe_push
(file_cache_slot::line_info (m_line_num,
m_line_start_idx,
diff --git a/gcc/params.opt b/gcc/params.opt
index 5d234a6..d84e356 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -136,10 +136,10 @@ Maximal estimated growth of function body caused by early inlining of single cal
-param=file-cache-files=
Common Joined UInteger Var(param_file_cache_files) Init(16) Param
-Max number of files in the file cache.
+Max number of files in the file cache. When 0 this is automatically sized.
-param=file-cache-lines=
-Common Joined UInteger Var(param_file_cache_lines) Init(100) Param
+Common Joined UInteger Var(param_file_cache_lines) Init(0) Param
Max number of lines to index into file cache.
-param=fsm-scale-path-stmts=