universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.51k stars 622 forks source link

Ruby: optimize the parser by reducing the numbers of calling strlen #3916

Closed masatake closed 8 months ago

masatake commented 8 months ago

About 20% faster with this change. Eventually, we have to switch to a token-based parser. This is just a way to extend the life of the current parser.

Without this change:

[yamato@dev64]~/var/codebase% for x in Ruby ; do ./codebase ctags --ctags ~/var/ctags-github/ctags $x; done
version: e3439eb0
features: +wildcards +regex +iconv +option-directory +xpath +json +interactive +sandbox +yaml +packcc +optscript +pcre2
log: results/e3439eb0,Ruby................,..........,time......,default...,2024-01-13-07:37:44.log
tagsoutput: /dev/null
cmdline: + /home/yamato/var/ctags-github/ctags --quiet --options=NONE --sort=no --options=profile.d/maps --totals=yes --languages=Ruby -o - -R code/katello code/metasploit-framework code/puppet code/rails code/redmine code/rspec-core code/ruby code/theforeman-puppet code/vagrant
20744 files, 2852961 lines (88272 kB) scanned in 4.0 seconds (22230 kB/s)
185632 tags added to tag file

real    0m4.171s
user    0m3.849s
sys 0m0.298s
+ set +x

With this change:

[yamato@dev64]~/var/codebase% for x in Ruby ; do ./codebase ctags --ctags ~/var/ctags-github/ctags $x; done
version: daa583dd
features: +wildcards +regex +iconv +option-directory +xpath +json +interactive +sandbox +yaml +packcc +optscript +pcre2
log: results/daa583dd,Ruby................,..........,time......,default...,2024-01-13-07:38:23.log
tagsoutput: /dev/null
cmdline: + /home/yamato/var/ctags-github/ctags --quiet --options=NONE --sort=no --options=profile.d/maps --totals=yes --languages=Ruby -o - -R code/katello code/metasploit-framework code/puppet code/rails code/redmine code/rspec-core code/ruby code/theforeman-puppet code/vagrant
20744 files, 2852961 lines (88272 kB) scanned in 3.3 seconds (26730 kB/s)
185632 tags added to tag file

real    0m3.492s
user    0m3.141s
sys 0m0.330s
+ set +x
codecov[bot] commented 8 months ago

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (be3439e) 85.34% compared to head (0daa583) 85.34%.

Files Patch % Lines
parsers/ruby.c 96.42% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3916 +/- ## ========================================== - Coverage 85.34% 85.34% -0.01% ========================================== Files 234 234 Lines 56010 56024 +14 ========================================== + Hits 47800 47811 +11 - Misses 8210 8213 +3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

masatake commented 8 months ago

Eventually, we will have to switch to a token-base parser.