The Ko compiler comprises two workflows, evaluator and weaver , which interpret the same language.
The evaluator executes Ko programs “on-the-fly” and it interrupts on type errors as they occur.
The weaver builds optimized Ko binaries and reports type errors at compile time.
The evaluator and weaver workflows excel in different application domains.
The evaluator is less performant, but it allows for rapid development and experimentation cycles.
The weaver is slower to build code all the way to machine level, but provides
code which is provably faster than hand-crafted optimizations (in any language).
The weaver and evaluator can also be used in conjunction with each other,
whereby the weaver is used first to verify program type safety, but not to generate code.
Consequently, an execution of the evaluator over the verified program is guaranteed
not to fail (equivalently, to be type-safe).
The evaluator is more appropriate in the following areas where instruction-level
speed optimizations are inessencial:
- Implementing build flows, for instance, as an alternative to Bazel .
- Implementing code-generation flows targeting generation
of interdependent configuration files, for instance, as an alternative to Jsonnet .
- Implementing content management systems.
(This simple wiki site is implemented in Ko.)
- Safely implementing (stateful) control-plane logic for
cloud systems, like Kubernetes .
- Implementing complex, modular, concurrent and synchronized scripts
for operations, in place of writing low-level Go code.
For instance, Ko programs utilizng basic stateless Kubernets primitives
can implement stateful control loops. Thus Ko provides an alternative to
stateful custom resource definitions in Kubernetes.
- Implementing application logic for programmable technologies,
like MapReduce mappers and reducers, where the cross-worker network latencies
may far exceed the per-worker computation times.
- Implementing database transactions at both high-level (using custom schemas
definable in Ko) or low-level (by programming at a service request/response level).
The weaver is more appropriate in the following areas:
- Implementing application logic in a technology-independent manner
in situations where highly-performant (i.e. technology-dependent) execution is required.
Exаmples include implementing various types of network middleware software
where the “application logic” is on the critical path. Some specific examples
are (i) programmable network proxies (at any protocol level),
or more recently (ii) policy evaluation frameworks controlling compute resources
at a fine grain level.
- Implementing technology-independent application logic, which can
be automatically translated to any target language (and hardware) technology.
Protocols, which add temporal behavior constraints on top of API definitions,
continue to be implemented in the form of client libraries for multiple languages
— manually. The Ko weaver provides a systematic path to solving this problem.
- Implementing encapsulated application logic which can be
run, paused and resumed on a different (if need be) platform, generically.