fs: seq_file: optimize seq_pad()
PATCH 1/1 fs: seq_file: optimize seq_pad()
Use seq_putc() instead of seq_printf() in seq_pad() because the former is faster.
--- fs/seq_file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/seq_file.c +4 -2
@@ -787,8 +787,10 @@ EXPORT_SYMBOL(seq_write);void seq_pad (struct seq_file *m,char c) {int size = m->pad_until - m->count; -if (size >0 ) -seq_printf (m,"%*s" , size,"" ); + +while (size-- >0 ) +if (unlikely (seq_putc (m,' ' ))) +return ;if (c)seq_putc (m, c); }
Signature · 1 line
1.9.1
Al Viro
maintainerQuoted 2 lines · Dmitry Voytik
Use
seq_putc()instead ofseq_printf()inseq_pad()because the former is faster.
_Solitary_ seq_putc() is certainly going to be faster, but that loop... Do you have profiling results, or is it just an apriori "printf must be sloooowwww"?
Quoted 7 lines · Al Viro
Quoted 2 lines · Dmitry Voytik
Use
seq_putc()instead ofseq_printf()inseq_pad()because the former is faster._Solitary_
seq_putc()is certainly going to be faster, but that loop... Do you have profiling results, or is it just an apriori "printf must be sloooowwww"?
My fail, sorry. The commit message is little bit wrong. I meant that simple looping of seq_putc() is faster than seq_printf(). I haven't done profilings. I just realized that seq_printf() is more complex than simple loop with seq_putc()
(no need to decode format string as in vsnprintf(), etc).
If I resend the patch with the following commit message:
Use a simple loop with seq_putc() instead of seq_printf() in seq_pad() as this approach is faster due to less complexity in terms of machine cycles.
Would be it Okay?
Thank you for reviewing.
Signature · 3 lines
Best Regards, Dmitry Voytik. [email protected]