Skip to content

Unbox across static handlers#8735

Merged
alainfrisch merged 2 commits intoocaml:trunkfrom
alainfrisch:unbox_across_static_handlers
Oct 3, 2019
Merged

Unbox across static handlers#8735
alainfrisch merged 2 commits intoocaml:trunkfrom
alainfrisch:unbox_across_static_handlers

Conversation

@alainfrisch
Copy link
Copy Markdown
Contributor

@alainfrisch alainfrisch commented Jun 14, 2019

This is a version of #2162, but built on top of the new (proposed) treatment of unboxing at the Cmm level (from #2165).

The first two commits are those from #2165. Only the third commit should be reviewer here, and this PR should not be merged before #2165.

@alainfrisch alainfrisch force-pushed the unbox_across_static_handlers branch from 46427c7 to fa94371 Compare June 14, 2019 13:28
@alainfrisch alainfrisch marked this pull request as ready for review June 14, 2019 13:29
@alainfrisch alainfrisch requested a review from mshinwell June 14, 2019 13:29
@alainfrisch alainfrisch force-pushed the unbox_across_static_handlers branch from fa94371 to b011ea9 Compare June 14, 2019 16:11
@alainfrisch
Copy link
Copy Markdown
Contributor Author

@lthls : would you like to review this one as well?

@alainfrisch alainfrisch force-pushed the unbox_across_static_handlers branch from dd36b56 to 6ab4a64 Compare September 17, 2019 10:30
Copy link
Copy Markdown
Contributor

@lthls lthls left a comment

Choose a reason for hiding this comment

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

I approve this pull request, both its objective and its implementation. There are a few remarks that I can make, tough:

  • If I understand correctly, after this gets merged we'll have catch handlers with non-val register types for the first time on trunk. I think this is already handled correctly, but I'll ask a few people around me who have experienced with register types if there's anything to watch for.

  • The notify_catch field of the environment is a bit unintuitive. Knowing what it tries to achieve, I understand how it works, but it could use a few lines of comments explaining what it's used for. I think that the natural solution would be to have the notify_catch field contain an unboxed_number_kind IntMap.t, but this would mean that the environment contains information that needs to be returned back to the caller, changing the signature of the transl* functions and updating the code everywhere. I see the proposed version here as a way around that problem, but it could do with a bit more documentation.

  • I'd be curious to know how often the No_result case occurs in transl_catch, and on which kind of programs. There's a number of optimisations that could be done if it happens, but I'd expect that either the optimisations are already done elsewhere or that this case never occurs in practice.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

Thanks @lthls. I've added some words about the notify_catch callback technique.

I'll ask a few people around me who have experienced with register types if there's anything to watch for.

I think all the cmm and post-cmm backend is ready to deal with non-val types (also for functions arguments, which is what I used in an experimental PR about unboxed calling conventions), but indeed, this hasn't received wide coverage. Did you more feedback from other people?

I'd be curious to know how often the No_result case occurs in transl_catch, and on which kind of programs.

I haven't been able to produce this situation (corresponding to a dead catch handler), and possibly this is excluded by other passes, but it would seem weird to reject the case at this point.

@lthls
Copy link
Copy Markdown
Contributor

lthls commented Oct 1, 2019

I think all the cmm and post-cmm backend is ready to deal with non-val types (also for functions arguments, which is what I used in an experimental PR about unboxed calling conventions), but indeed, this hasn't received wide coverage. Did you more feedback from other people?

Yes, they confirmed that they didn't find any bugs linked to this change in their experiments.

I haven't been able to produce this situation (corresponding to a dead catch handler), and possibly this is excluded by other passes, but it would seem weird to reject the case at this point.

I wasn't thinking about rejecting the case, I would have simply removed the handler since it's unreachable. If you haven't encountered such a situation in practice, it's probably not worth worrying about.

Thanks for addressing my concerns.

In the light of the recently merged #8584, do you want to take the opportunity to show some of the improvements that one can expect ? Your original pull request (#2162) showed some of the cases where it would trigger, maybe you could build a micro-benchmark based on these.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

Sorry, I should indeed have put a link to #2165 (comment) which still applies (just checked).

@alainfrisch
Copy link
Copy Markdown
Contributor Author

(That's a 40% speedup on the micro-benchmark.)

@alainfrisch
Copy link
Copy Markdown
Contributor Author

Based on @lthls 's approval and the availability of the micro-benchmark above, I'll merge this soon if nobody complains.

@mshinwell
Copy link
Copy Markdown
Contributor

@alainfrisch Have you obtained any benchmark numbers from larger programs with this patch? It seems a significant enough change to be worth doing so.

As an aside, I think the existing register typing for unboxed integers is dubious, as they are assigned type Int. However this could in theory be joined with Val to yield Val, which would be wrong for e.g. a boxed int64. I suspect such a join never happens for a register holding a value that arose from unboxing, but this should probably be fixed nonetheless. My previous PR on improved register typing, which has been taken over by @Gbury (in conjunction with work on register type inference, as discussed at the last dev meeting), should be sufficient.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

@alainfrisch Have you obtained any benchmark numbers from larger programs with this patch? It seems a significant enough change to be worth doing so.

No visible change on some larger payloads I tried, but we wrote our critical numerical code knowing how unboxing works currently, and carefully rewrote parts to workaround current limitations. This ends up with some code like:

  let a = ref 0. and b = 0. in
  if cond then (a := ...; b := ...) else (a:= ...; b := ...)

which could be avoided by a simple unboxed float tuple binding with this PR.

I suspect such a join never happens for a register holding a value that arose from unboxing, but this should probably be fixed nonetheless.

If there is a problem, I think it already exists with normal unboxing of let-bound identifiers. Here we unbox catch arguments if they are boxed numbers for sure, considering all call sites; and for the "continuation" (i.e. the handler code), it is as if we inserted a local let-bound identifier to hold the unboxed value (let argi_unboxed = unbox argi in ...).

@mshinwell
Copy link
Copy Markdown
Contributor

I think the typing problem isn't specific to this PR, agreed.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

@mshinwell : are you ok with merging?

@mshinwell
Copy link
Copy Markdown
Contributor

I think as long as you're satisfied with the potential performance changes, it's fine.

@alainfrisch alainfrisch closed this Oct 2, 2019
@alainfrisch alainfrisch reopened this Oct 2, 2019
@alainfrisch
Copy link
Copy Markdown
Contributor Author

Closed/reopened to relaunch Appveyor CI, which took significantly longer than usual (and one job was killed because of it); no problem on Travis, so I suspect a transient issue on Appveyor, but let's be sure before merging.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

Ok, AppVeyor finished each job in < 1 hour, but job time seems to be significantly higher than on master; I think it's worth investigating before merging.

@alainfrisch alainfrisch closed this Oct 3, 2019
@alainfrisch alainfrisch reopened this Oct 3, 2019
@alainfrisch
Copy link
Copy Markdown
Contributor Author

False alarm, the latest AppVeyor build is a fast as usual (also confirmed by checking AppVeyor logs that slow builds were also slow on the bytecode parts).

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.

4 participants