Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-7301

Avoid excessive type inference when checking instance_of?

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: PUP 4.9.3
    • Fix Version/s: PUP 4.9.4
    • Component/s: None
    • Labels:
    • Template:
    • Acceptance Criteria:
      Hide

      That the benchmark in PUP-7294 shows performance numbers for 4.9.x that is at least on par with the performance in Puppet 4.8.2

      Show
      That the benchmark in PUP-7294 shows performance numbers for 4.9.x that is at least on par with the performance in Puppet 4.8.2
    • Team:
      Puppet Developer Experience
    • Story Points:
      2
    • Sprint:
      PDE 2017-03-08
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      This change decreases the number of type inferences that are performed during normal execution. This increases performance on large hiera datasets and hierarchies.
    • QA Risk Assessment:
      No Action
    • QA Risk Assessment Reason:
      performance in reading in hierarchies in hiera/lookup

      Description

      The type of an instance is often inferred when checking if it is instance of a Pcore type. I.e:

      t.instance_of?(o)
      

      can be written as:

      t.assignable?(<inferred type of o>)
      

      While this makes the instance check very simple and elegant, inferring a type can be very expensive in terms of CPU. Especially if the o is a large data structure. This means that inferring the type should not be done unless there's a real need for it. Consider the case where t is the type Scalar and o is a huge hash. There's no need to infer the type of o since it's already a known fact that a hash isn't a scalar.

      In addition to the Scalar example, there are a couple of similar low hanging fruits that needs to be fixed in the Pcore type system.

      The problem became very apparent in 4.9.x where the type of loaded Hiera data hashes is asserted. See PUP-7294 for more info.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            thomas.hallgren Thomas Hallgren
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support