LibCST/docs/source/experimental.rst
Benjamin Woodruff 88ac18872c Add a reentrant (incremental) codegen API
**Context:** This is an experimental performance optimization that we're
hoping to use for our internal linter at Instagram. I added some
documentation, but it's unsupported, and isn't very user-friendly.

This adds `ExperimentalReentrantCodegenProvider`, which tracks the
codegen's internal state (indentation level, character offsets,
encoding, etc.) and for each statement, it stores a `CodegenPartial`
object.

The `CodegenPartial` object has enough information about the previous
codegen pass to run the codegen on part of a tree and patch the result
back into the original module's string.

In cases where we need to generate a bunch of small independent patches
for the same file (and we can't just generate a new tree with each patch
applied), this *should* be a faster alternative.

I don't have any performance numbers because I still need to test this
end-to-end with our internal codebase, but I'd be shocked if it was
slower than what we're doing.

This could theoretically live outside of LibCST, but it depends on a
whole bunch of LibCST internals, so there's some value in making sure
that this is in sync with the rest of LibCST.
2019-10-28 17:23:26 -07:00

15 lines
460 B
ReStructuredText

.. _libcst-experimental:
=================
Experimental APIs
=================
These APIs may change at any time (including in minor releases) with no notice. You
probably shouldn't use them, but if you do, you should pin your application to an exact
release of LibCST to avoid breakages.
Reentrant Code Generation
-------------------------
.. autoclass:: libcst.metadata.ExperimentalReentrantCodegenProvider
.. autoclass:: libcst.metadata.CodegenPartial