Reduce the number of heap allocations in KsymIter::from_kallsyms() by
replacing lines() with read_line() + a reusable buffer.
using iterators directly instead of collecting the result of line.split() into a vector.
Test Plan
Unit tests
Benchmark results on a test kallsyms file containing 1013568 lines. I consistently observed similar improvements for a file with 675712 entries. However, it's worth noting that I don't see the same performance gains when I run this against a file with 337856 entries.
Benchmarking Read /proc/kallsyms/Measure read all ksyms: Warming up for 5.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.4s, or reduce sample count to 50.
Read /proc/kallsyms/Measure read all ksyms
time: [84.522 ms 84.705 ms 84.871 ms]
change: [-24.298% -24.049% -23.840%] (p = 0.00 < 0.05)
Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
3 (3.00%) low severe
5 (5.00%) low mild
4 (4.00%) high mild
1 (1.00%) high severe
Context
KsymIter
Changes
KsymIter::from_kallsyms()
bylines()
withread_line()
+ a reusable buffer.line.split()
into a vector.Test Plan