(PUP-751) Check for reparse once per compile

Previously, whenever the known_resource_types
(Puppet::Resource::TypeCollection) was retrieved from the
environment it would check if there were any files that needed to be
reparsed. If any files needed a reparse, then the entire TypeCollection
was thrown away and redone.

In most cases the reparse check did not need to touch the filesystem
because the Puppet::Util::PeriodicWatcher would return a cached result
until the filetimeout had expired. Unfortunately the check was done so
often that the overhead of simply checking if enough time had passed
caused it to take a considerable amount of time.

This changes it so that the environment's known resource types are only
recalculated if the new check_for_reparse method determines that it
should. The new method is only called at the beginning of a compile and
so the files will never be checked while a compilation is being
executed.

In my local benchmark runs (the many_modules benchmark) this resulted in
a speedup from ~0.8 seconds to ~0.6 seconds.
(maint) Optimize adding tags

Resources add a lot of tags and so streamlining that ends up with a
overall savings for catalog compilation. This removes an extra call to
collect, removes several method calls, and relies on the fact that the
@tags object is a set and so we don't need to check for the tag already
being there.
(maint) Use JSON for parsing metadata.json

Now that puppet depends on JSON we can use it to parse the metadata.json
file. The built in json parsers will be much faster than PSON.
(maint) Remove String check

There isn't any need to check for the String class because it also
responds to to_str. This reduces the number of calls in the case of
things that respond to to_str
(maint) Reduce calls to settings

During the lifetime of a scope object the value of the trusted data
settings should not change. Rather than looking this up on every
invocation of setvar, which is fairly expensive, the scope can simply
hold onto the value from when it was instantiated.
(maint) Hold token name in local variabel

The tokens name was fetch multiple times in quick succession. The lexer
is in a very tight inner loop and so any reduction of method calls can
produce improvements in performance. Although most work for language
performance is focussed on the new parser, this is a simple, small win
that we can easily take now.
(PUP-751) Benchmark defined resource types

This adds a benchmark for compiling defined resource types. There are
simply multiple modules that have a single defined resource type in
each. The site.pp produces 2 instances of each defined type.

Current timings on my local machine:

                     user     system      total        real
    Run 1        0.780000   0.150000   0.930000 (  0.935276)
    Run 2        0.760000   0.140000   0.900000 (  0.901496)
    Run 3        0.780000   0.130000   0.910000 (  0.912020)
    Run 4        0.780000   0.130000   0.910000 (  0.917095)
    Run 5        0.780000   0.130000   0.910000 (  0.908075)
    Run 6        0.810000   0.140000   0.950000 (  0.950874)
    Run 7        0.820000   0.130000   0.950000 (  0.948420)
    Run 8        0.780000   0.140000   0.920000 (  0.918298)
    Run 9        0.780000   0.130000   0.910000 (  0.905121)
    Run 10       0.770000   0.130000   0.900000 (  0.903823)
    > total:     7.840000   1.350000   9.190000 (  9.200498)
    > avg:       0.784000   0.135000   0.919000 (  0.920050)
(PUP-751) Preserve environment across resource copy

The resource's environment was lost when a copy was made. This caused
the type information to be looked up again, from scratch, as well as a
total loss of the associated environment information (it would switch
from one environment to another). By preserving the environment any
calls to resource_type, or other methods that require the environment,
are much faster.

This also preserves the rstype cache of the resource_type to cut down
the looks a slight amount more.

Here is the breakdown of the speedups to this point on my machine:

Initial(bca4d4e):
> total:     7.520000   1.250000   8.770000 (  8.789636)
> avg:       0.752000   0.125000   0.877000 (  0.878964)

Prefer defined types(2617d61):
> total:     7.150000   1.170000   8.320000 (  8.326319)
> avg:       0.715000   0.117000   0.832000 (  0.832632)

Preserve environment(3f8e94c):
> total:     6.170000   0.860000   7.030000 (  7.057820)
> avg:       0.617000   0.086000   0.703000 (  0.705782)

I also tried to change the order of loading in
Puppet::Parser::Scope#find_resource_type to have it look for defined
types first, but that resulted in an overall slowdown:

> total:     6.740000   0.730000   7.470000 (  7.476968)
> avg:       0.674000   0.073000   0.747000 (  0.747697)
(maint) Fork for each scenario

Because of the way puppet initializes, we can't safely re-initialize in
the same process. In order to run all of the scenarios we need to make
sure there is a new process for each one. This changes from having the
"all" tasks re-run rake for each of these instead of just making them
dependencies of the "all" task.
(PUP-751) Ensure resource knows it's type

By looking up the definition first, many tests were broken because of
expectations about filesystem access. By ensuring that the resources
are created with the expected resource_type there isn't any lookup
neccessary.
(PUP-751) Fix resource_type to check for changes

Since known_resource_types on the Environment no longer checks for stale
files, any users of that are going to be working in a long running
process need to ensure that the stale check is made before trying to use
the known_resource_types. The only place, besides the compiler, that
does this is the resource_type indirection. This adds that check there.
Merge pull request #2341 from zaphod42/issue/master/pup-751-define-type-benchmarks

(PUP-751) Benchmark and optimize loading of defined types