-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ActiveSupport's Object#blank? directly #16259
Conversation
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/filters.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/indent.rb | ||
|
||
# Ignore partially included gems where we don't need all files | ||
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/*/*.jar | ||
**/vendor/bundle/ruby/*/gems/i18n-*/lib/i18n/tests* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The i8n
cleanup is unrelated, it should have been included in #15311
Let me know if you'd like a cleaner diff, and I can move this to a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dduugg Fine with me as-is, thanks!
end | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def present? # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR uses the latest version of the code, bc we're no longer contained by version compatibility of ActiveSupport as a whole. This includes changes such as rails/rails#49909, captured here.
It looks like, in ActiveSupport and as vendered before, their implementation is/wss under '
(* There's already a to-do note in ' |
Because there are 10 classes being monkey-patched within the file for various optimization purposes, so |
Just curious: what would/might happen if you'd try to factor the 'specializations' out into their own, separate files; does that break or not work? (Probably not worth trying or worth the complexity, though; the point you made stands. Further, Ruby's duck/dynamic typing makes any even superficial thought of or attempt at exercising genrric programming kind of moot and a pointless thought experiment; there isn't any non-genrric programming. If anyone feels like iterating on code structure later, they can do that then, anyway.) |
@RandomDSdevel Your review is not required on this PR, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really happy with this so far, thanks @dduugg! The amount of lines of vendored code removed is 😍. A few questions I was unclear about:
- how does
blank.rb
now differ from the upstream version(s)? - was
concurrent-ruby
removal done by us/upstream/both? - how will this be kept up-to-date? Is there any need to do so?
- if we don't plan on keeping up-to-date: what do you think about stripping a bunch of the documentation/comments/any specialisations we don't really want or need?
Thanks again, suspect this will be mergeable very soon.
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/filters.rb | ||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/indent.rb | ||
|
||
# Ignore partially included gems where we don't need all files | ||
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/*/*.jar | ||
**/vendor/bundle/ruby/*/gems/i18n-*/lib/i18n/tests* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dduugg Fine with me as-is, thanks!
The major one is a non-concurrent cache for encodings that error: ccbb05d ccbb05d (I suspect this is better for us - Homebrew is primarily single-threaded, so this should be more performant. It also allows us to drop
Us, as described above.
It will be on us to maintain. The upstream history shows a pair of very minor performance improvements in the past two months, otherwise the last code change was adding support for multiple encodings in 2017. (I can imagine writing tests to verify implementations match the upstream source, but that seems like overkill)
We could do that, although we kept the documentation in the other instance that I'm aware of us incorporating ActiveSupport extensions (and we also attached the rails license as a comment): https://github.com/Homebrew/brew/blob/master/Library/Homebrew/extend/array.rb#L5-L50 |
All seem like great, appropriate changes 👍🏻
Cool, fine as-is then 👍🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here again @dduugg!
Per the code comment, it seems I should bump this after ignoring a pair of committed vendored gems in #16259 : https://github.com/Homebrew/brew/pull/16259/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947R102 https://github.com/Homebrew/brew/pull/16259/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947R109
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?As mentioned in #16190 (comment) this PR uses direct implementations of
ActiveSupport
'sblank?
monkey-patches. (The code is published under the MIT license, allowing it to be copied/modified/distributed/etc. without limitation).The implementation does not use caching for strings with multiple encodings, as introduced in https://github.com/rails/rails/pull/31049/files, as this seems like quite the edge case to bring in
concurrent-ruby
for (it also shave 10ms or so off of every brew command that doesn't make use of the cache). (We could possibly use a builtin Ruby Hash for caching as a compromise, but that also seems more trouble than it is likely to be worth.)(Note that
Library/Homebrew/extend/blank.rb
breaks the pattern of other files withinLibrary/Homebrew/extend/
, which are mostly concerned with patching a single module (and named accordingly), while this file introduces optimizations for several subclasses.)By removing unused dependencies, this PR also reduces both the file and line count of the repo by > 5%.