Skip to content

Utilizing pickled environments to optimize build time #282

Description

@jptelle

Hello all,

First off, thank you for developing and maintaining such an incredible utility. My team uses this extension to its fullest capacity and we have had great results so far. Please scroll to the bottom of the post if TLDR to see the emboldened question.

Our software is composed entirely of Matlab code that is heavily abstracted and distributed in several packages. There are nearly 2k scripts, and the size of the project has warranted the development of a proprietary utility for parsing out the codebase and generating the rST file structure before building with Sphinx. Everything is documented using the automodule, autoclass, autofunction, etc. directives.

In the day-to-day development process, our team spends a considerable amount of time formatting comments within the Matlab scripts such that they render properly in the generated documentation. We've noticed that, upon calling sphinx-build, the sphinxcontrib-matlabdomain extension files through and processes every script that is referenced in the index. This is indicated by the following output in the build log:

Running Sphinx v8.2.3
[sphinxcontrib-matlabdomain] matlab_short_links=True, forcing matlab_keep_package_prefix=False.
loading pickled environment: The configuration has changed (22 options: 'applehelp_bundle_name', 'applehelp_kb_product', 'applehelp_title', 'author', 'datatables_version', ...)
done
building [mo]... targets for 0 po files that are out of date
writing output
building [html]... targets for 345 source files that are out of date
updating environment... [config changed ('project')] 345 added, 0 changed, 0 removed

There are a total of 345 rST files that contain directives referencing all of the scripts in our codebase. Thus, the output indicates that all of the source files are "out of date". Even if we build the documentation twice consecutively with zero changes to the source files, the same behavior ensues. Functionally, there is no problem with this. However, it does add considerable overhead to the build time and thus significantly increases the time required to document scripts, since the developer often checks their work throughout the process. The compilation time varies by machine, but it has been reported in the range of 1 to 10 minutes.

We are looking to implement a "preview" feature for the purpose of trimming down this build time, but the best solution we've proposed thus far seems to be a bit hacky, e.g.:

  1. Create a temporary "micro-project" in the OS-specific temp directory
  2. Copy just the Matlab file in question to the source directory
  3. Build the micro-project with Sphinx
  4. Transfer the corresponding generated file to the parent docs directory and view

This method has an obvious downside in that interlinking will not work for the previewed document. It is merely intended as a stopgap solution to ensure formatting is correct before building the entire codebase documentation.

TLDR: My question is: Is enabling compatibility of this extension with Sphinx pickled environments feasible, such that it can detect when referenced scripts have changes and build accordingly? If not, would a workaround be worth considering, such as a hook for specific paths to scripts that need to be processed/omitted?

Hopefully I've contextualized the problem sufficiently. I understand this is a bit beyond the pale in terms of the use case of this extension, but your consideration is much appreciated. Thank you for your time, and please let me know if you require more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions