Skip to content

Cheap and greedy generator for common usage pattern #148

@crisptrutski

Description

@crisptrutski

Hey,

Busy looking at improving build performance, specifically heavy use is being made of Traceur and compile times increase dramatically when sourcemap generation is enabled.

The usage pattern of SourceMapGenerator via Traceur is very predicable:

  1. Mappings always are always of the "size 4" variety (no name)
  2. Sources are all known in advance
  3. Mappings are all added in-order

Seems possible one could encode mapping strings greedily, skipping edge cases, intermediate representation, deferred computation etc.

Also imagine this usage pattern to be very common in other compilers. (The assumption of "no names" could relax to "name list known in advance" with only marginal extra overhead)

Perhaps something like the following:

  class OptimizedSourceMapGenerator {
    // Note that `sources` and `names` are now required
    constructor(file, sourceFileRoot, sources, names, [sourcesContents])

    // Assume (or assert) called with (generatedLine, generatedColumn) strictly ascending
    // This is the only retained public method from regular implementation, beyond toString, toJSON
    addMapping(generatedLine, generatedColumn, originalLine, originalColumn, source, name)
  }

Not sure how much this would impact performance, but have a hunch that it could be large!

Would appreciate feedback on whether:

  1. There seems to be merit in this approach, or whether you'd anticipate little improvement
  2. You have other suggestions
  3. PR welcome here for this, or best left as a 3rd party extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions