Implements std.reverse in native Go, improving performance
benchmark old ns/op new ns/op delta
Benchmark_Builtin_reverse-16 869191619 231309458 -73.39%
part of #111
This pulls in the implementation of substr into native Go instead of interpretted Jsonnet.
benchmark old ns/op new ns/op delta
Benchmark_Builtin_substr-16 97121527 15115905 -84.44%
part of #111
When adding long strings, don't copy them immediately. Instead
build long strings only when their contents are requested.
This allows to build a long string from parts, using a regular
operator+ in linear time. This lets users to worry much less
about using std.join etc.
If indexing the string is mixed with building it using operator+
the behavior can still be quadratic. We may want to address it in
a later change.
Sort is something that is highly optimized in most languages
and users can expect it to be fast. We can piggyback on
the Go implementation.
This change results in 100x speedup on bench.06.jsonnet.
This change adds caching to objects fields, i.e. now subsequent
references to an object field are going to be served from cache.
Cache is kept within an object. Objects created with operator +
start with a clean cache (they have to, because in general all
the fields may have changed their values due to late binding).
This change comes naturally with a change of structure of objects,
now valueObject is a concrete struct which keeps "uncachedObject"
which is roughly equivalent to old objects.
We didn't set the environment (upvalues) for objects
created as comprehensions - we set them for each field
separately, but that meant missing the locals.
Keep object locals only once in AST
For example this reduces the size of stdlib ast file
roughly 3x. Note that this change doesn't regenerate the stdlib,
so that the diff here is sane.
It is likely to slightly improve performance of code using
a lot of locals (~10% on bench.05.gen.jsonnet).
The desugaring is more strightforward now, and we're back
to desugaring each node exactly once.
People use these operators in tight loops, without even
thinking about it, and it's previous implementation required
multiple object lookups (std.), string comparisons (for types)
and multiple jsonnet function calls.
This change introduces builtin, efficient implementation.
It results in ~3x speedup in strContains benchmark that
Angus provided on Slack.
Additional benefit is that equals/primitiveEquals distinction
is now obsolete, which made things simpler for everyone.
It seems like it was broken on older compilers
since pregenerated stdlib AST.
It adds go 1.8.x to travis, so that we have a chance
of catching when our "known to work" no longer holds.
Actually there was one (objectFieldEx) that was inconsistent, i.e.
it was available by a different name from what appeared in the stack
trace. This is now fixed.
* Location, error formatting and stack trace improvements
* Static context for AST nodes
* Thunks no longer need `name`
* Prototype for showing snippets in error messages (old format still
available)
* Use ast.Function to represent methods and local function sugar.
* Change tests so that the error output is pretty
This is necessary for example for native functions
(which take json as arguments).
Standard "encoding/json" representation is used, but I have
mixed feeling about it. Not sure if treating json values as interface{}
is the right trade-off in our case.