Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Optimize expensive XPath expressions in HTML transform #165

Merged

Commits on Feb 6, 2023

  1. Add snapshot tests to catch regressions not covered in tests

    This commit has been cherry picked from its original appearance in enketo#164, with the following changes:
    
    - Include all enketo-core fixtures in preparation for adding benchmarks to establish a performance baseline.
    - Temporarily increase the timeout for snapshot tests so that the longer running enketo-core fixtures can generate initial snapshots.
    - Restore test shuffling (turning that off was a mistake in the original TypeScript PR).
    - Switch the default test reporter to `dot` to improve visibility of progress during test runs (it's still not great, mainly due to performance).
    - Move `linkedom` stuff to `/test/shared.ts` as it will only be used in tests.
    - Accept updates to `package-lock.json` with SHA-512 integrity hashes.
    - Excludes formatting of XML/XSL.
    
    About snapshot serialization:
    
    Snapshots use a custom serializer designed to identify only meaningful differences. This means that a snapshot matches if:
    
    - the value is exactly equal
    - the value is equal, apart from insignificant changes to whitespace and/or attribute order
    
    The serialization logic:
    
    1. Manually ensures consistent attribute order (using `linkedom` as a DOM compatibility library, primarily because its types are much better than those for `@xmldom/xmldom`).
    2. Uses `prettier` to normalize whitespace.
    3. Uses `pretty-format` (`vitest`'s default) for final serialization.
    
    Apart from adding snapshots, tests have been updated to reference `linkedom`'s types (corrected where necessary) and to its behavior (which is semantically equivalent to the previous `@xmldom/xmldom` usage, but more consistent with a real DOM environment).
    eyelidlessness committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    485730c View commit details
    Browse the repository at this point in the history
  2. Add benchmarks

    This is almost entirely different from the original in enketo#164. Instead it:
    
    - uses benchmark.js rather than implementing our own
    - mostly defers to benchmark.js stats logic for reporting
    - skips `@actions/core` for generating the GitHub Actions summary, it wasn't really doing a lot for us
    eyelidlessness committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    3048222 View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2023

  1. Configuration menu
    Copy the full SHA
    0f826fb View commit details
    Browse the repository at this point in the history
  2. Optimize expensive XPath expressions in HTML transform

    This should have little impact on forms which already transform quickly, but it dramatically improves the time to transform forms which are particularly slow. In my testing, this is especially the case for forms with a large number of translations/itext values.
    
    The improvement comes from using `xsl:key` elements to reference the expressions identified as expensive, and to look them up with the corresponding `key` XPath function. My strong assumption is that the reason this has such a big impact is that the non-key references are rerun on each visit to their respective `xsl:template` or upon each reference to a top-level `xsl:variable`, whereas `key` presumably pre-caches the expression's nodeset and only filters based on the `use` argument.
    eyelidlessness committed Feb 7, 2023
    Configuration menu
    Copy the full SHA
    a450673 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ba6f59a View commit details
    Browse the repository at this point in the history
  4. Fix: ensure snapshots match when version matches the current package.…

    …json version
    
    Otherwise snapshots will not match as soon as we prepare release
    eyelidlessness committed Feb 7, 2023
    Configuration menu
    Copy the full SHA
    004d045 View commit details
    Browse the repository at this point in the history
  5. Fix: prepare script ensures build before release

    This has been validated locally in enketo-core and enketo-transformer using `npm link`.
    eyelidlessness committed Feb 7, 2023
    Configuration menu
    Copy the full SHA
    03fbafa View commit details
    Browse the repository at this point in the history