Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1354

Long code blocks with multiple try/catch are expensive to compile

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 23.0
    • Fix Version/s: None
    • Component/s: compiler
    • Labels:
      None

      Description

      The following Erlang module takes a long time to compile from 23.0:

      -module(bar).
      -export([bar/0]).
      bar() ->
        try foo:bar() after foo:bar() end,
        % ... repeat the same line 300 times
        ok.
      

      A complete module can also be found here: https://gist.github.com/josevalim/32056b466d25bc253f4d2af885c56dea

      The culprit is beam_ssa_opt with most time spent on beam_ssa_type:join_types_1/3 (as shown by eprof). The issue is that we are comparing really large sets (100+ elements) and that takes time.

      One idea I had to fix this was: since infer_types_br knows which types it is adding to the type database, we could track the additions/removals instead of comparing type databases. Unfortunately I was not able to complete this particular patch. There may also be simpler solutions here, given try/end blocks that do not leak variables, but I am not familiar enough with the SSA stuff to figure it out.

      Thank you!

        Attachments

          Activity

            People

            Assignee:
            john John Högberg
            Reporter:
            josevalim José Valim
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: