Skip to content

Kill all use of Arity+#6585

Merged
enebo merged 7 commits intojruby:masterfrom
enebo:remove_block_stuff
Mar 3, 2021
Merged

Kill all use of Arity+#6585
enebo merged 7 commits intojruby:masterfrom
enebo:remove_block_stuff

Conversation

@enebo
Copy link
Member

@enebo enebo commented Mar 1, 2021

This branch was originally opened to solve some block problems but I quickly ran into use continuing to use Arity over Signature.

So nearly all of this is removing use of Arity from our code base (jruby-rack still uses a single Arity path in our codebase).

There are two block changes as well:

  1. IRRuntimeHelpers.prepareProcArgs had a check in covertValueIntoArgArray asking whether it is NORMAL. It is always a PROC so I just made that argument false.
  2. Block.prepareArgumentsForCall had extra logic to reduce the args array. This is just extra work which later code gets no benefit from.

As for Signature code migration it is large but pretty straight-forward. We calculate arity values for populators and we probably could do that differently in a post-Arity world but that is a topic for another day. The perf aspect is worth repeating (from 9ccc321):

"On the performance front we will do less work (although I doubt we will
see much we can measure). In startings up Rails server on a single
controller app we were doing 3k arity calcs and over 400k signature calcs.
Now we are doing no arity calcs and only 2k signature calcs. With some
better mechanism for Signature creation we could get this down to a few
hundred. The second aspect of this is reducing memory about 1Mb for the
same Rails app. Signature is about 100k now but since it is immutable we
can reduce this down to close to 0 if we share all combos during creation."

The other thing which could/should happen post commit is to make a better mechanism for sharing the same signatures so we create less instances. Right now a small Rails app makes 100k heap worth of Signatures but there are probably only a hundred or two hundred signatures which could exist (note: this was much larger number before this work). That would make the heap size very small. As it is this is about 0.1% of the heap for the Rails app. Making it 0.01% is nice but not worth a lot of effort.

Check removed with assumption that only PROC will use it.
We have had a long-term goal to replace Arity with Signature (started in
2014?).  The main issue is that Arity had no concept of keyword arguments.
The math behind arity lives on via Ruby's arity method but the underlying
structure needs more information.

This commit completely deprecates all use of arity internally.  There
are a few removals of long deprecated code using Arity but we still have
a lot of deprecated code just in case.  For example, jruby-rack still
depends on this on one constructor still which receives Arity.

Anything which was using arity is now written in terms of Signature.  The
largest missing piece of DynamicMethod not having a getSignature.  As
mentioned in the last paragraph we only have a single live code path using
Arity from jruby-rack.

On the performance front we will do less work (although I doubt we will
see much we can measure).  In startings up Rails server on a single
controller app we were doing 3k arity calcs and over 400k signature calcs.
Now we are doing no arity calcs and only 2k signature calcs.  With some
better mechanism for Signature creation we could get this down to a few
hundred.  The second aspect of this is reducing memory about 1Mb for the
same Rails app.  Signature is about 100k now but since it is immutable we
can reduce this down to close to 0 if we share all combos during creation.

The more near term motivation was seeing a mixture of logic between arity
and signature involved in block argument processing.  This branch has already
removed some complexity of block processing but every extra detail we need
to keep in our head makes fixing block issues that much harder.
@enebo enebo requested review from headius and kares March 1, 2021 18:55
Copy link
Member

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice to see the deprecated Arity param methods removed

@enebo
Copy link
Member Author

enebo commented Mar 2, 2021

@kares honestly there are a ton which should be but jruby-rack popped out as a currently using Arity consumer and I wonder if there are others. So I removed a few which seemed unlikely to be used and got frightened of removing more.

We really need a nice way of auditing all the external java exts.

@@ -1,4 +1,5 @@
/***** BEGIN LICENSE BLOCK *****
/*
**** BEGIN LICENSE BLOCK *****
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup. Make sure any unused Arity imports have been cleaned out.

@@ -1,4 +1,5 @@
/***** BEGIN LICENSE BLOCK *****
/*
**** BEGIN LICENSE BLOCK *****
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳

@@ -1,4 +1,5 @@
/***** BEGIN LICENSE BLOCK *****
/*
**** BEGIN LICENSE BLOCK *****
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳

@enebo enebo merged commit bb5a9ab into jruby:master Mar 3, 2021
@enebo enebo added this to the JRuby 9.3.0.0 milestone Mar 3, 2021
@enebo enebo deleted the remove_block_stuff branch March 4, 2021 15:52
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.

3 participants