Skip to content
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

Change ValueObject initializer #64

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

pjaspers
Copy link
Contributor

@pjaspers pjaspers commented May 4, 2020

So while testing support for multiple rubies: see #63 (which is also included in this one) we ran into some deprecations in ruby 2.7, these had the following characteritic:

class Hi
  def initialize(hash)
    puts hash
  end
  def self.with(hash)
    new(hash)
  end
end
class HiAgain < Hi
  def initialize(it: "me")
  end
end
hi = Hi.with(it: "me")
HiAgain.with(it: "stinkt")

The Hi.with is fine, that's just a hash, but when we use the HiAgain class with a keyword initializer, ruby will complain that we're using the last arguments as keyword arguments and that will break in ruby 3. (We're passing keyword args to a hash param)

The obvious solution would be to ** double splat, but that comes at quite a performance cost.

So this takes a different approach, by copying/stealing some code from Sequel to have our ValueObject be configured with the fields once, and then setting the values to one hash in instance variable.

The good news is that it does shave off some allocations, the bad news is that I don't see any real performance benefit. So keeping this in draft for now.

@pjaspers
Copy link
Contributor Author

pjaspers commented May 4, 2020

@mestachs I'd be curious to know if this is performing better on Linux than on Mac

The other thing is, I think I might have made loading from yaml slower, so that will be annoying as well to compare (since both this spec suite, and the 'data-tests' in orbf2 use it as well)

But for what it's worth on travis it seems to behaving similarly to master (7.74s vs 7.75s)

@pjaspers pjaspers mentioned this pull request Sep 14, 2020
@pjaspers
Copy link
Contributor Author

@pjaspers rebase this against latest

pjaspers and others added 9 commits March 3, 2022 17:53
This is mostly to do with the keyword arguments being more
strict. Where we used to be able to just throw a hash to a method, we
now need to explicitly tell ruby to treat the hash as keyword
arguments. This fixes these calls.

We have a couple of places in our used gems where this still pops up:

      /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dentaku-3.3.4/lib/dentaku/exceptions.rb:95: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
      /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dentaku-3.3.4/lib/dentaku/exceptions.rb:78:
      warning: The called method `initialize' is defined here

And

      /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dhis2-2.3.8/lib/dhis2/collection_wrapper.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
      /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dhis2-2.3.8/lib/dhis2/api/analytic.rb:7: warning: The called method `list' is defined here
Explicitly install newer bundler (travis defaults to 1.x bundler), on
ruby 2.7 this step isn't needed, but the other ones do need it.

Since the bundler will be cached after the first install let's keep it
like this.
Instead of looping and settings isntance variables, this will create
the model once (with the right attrs) and then do as little as
possible to set them.

In order for this to work, I've had to hunt down each `new` and
replace it with a `with`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant