lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.95k stars 398 forks source link

Avoid extra allocations when checking for namespace separators #1451

Closed ghost closed 1 year ago

ghost commented 2 years ago

Description

Hi, I am trying to optimize YARD a bit to speed up documentation runs on a large codebase.

The codebase is private, so I am using https://github.com/watir/watir/ as a smaller stand-in to report benchmarking numbers from https://github.com/SamSaffron/memory_profiler.

Test set-up

Performance data

Completed Tasks

ghost commented 2 years ago

This feels like a brittle change. NSEP is not guaranteed to be 2 characters, and thus, any changes away from a Regex would require a more generalized string comparison.

Even though this might seem like the :: separation is fairly baked into the Ruby language, YARD does allow for extensions to modify the source types being parsed (yard-js is one example), and this would break those plugins.

It's a pretty minor change (suggestions already provided) but I'm wondering if this significantly affects the performance improvements?

Thanks for taking a look. I can re-test this week, but I just wanted to note that existing code seems to assume that NSEP is two characters:

https://github.com/lsegal/yard/blob/8e82a8ab27f2e711bf555bb6ba0c037a1eb3ccfb/lib/yard/code_objects/proxy.rb#L37-L40

https://github.com/lsegal/yard/blob/15c8b888c52a9bcad498c4281004969fda6f87eb/lib/yard/code_objects/base.rb#L199-L202

Do these spots need to use NSEP.size as well?

ghost commented 1 year ago

I will not have time to work on this branch in the short term