endo icon indicating copy to clipboard operation
endo copied to clipboard

Import tracer

Open kriskowal opened this issue 1 year ago • 2 comments

What is the Problem Being Solved?

Bundles tend to get big and we notice when they can’t be posted to an Agoric blockchain with a message size limit, for example. They get big because modules get entrained by import and we need a way to investigate why they got entrained and how many bytes they (shallowly, transitively, differentially) contributed to the bundle. So, a tool like yarn why, but for modules instead of packages would be in order.

Description of the Design

A CLI tool, tentatively bundle-why would take bundle-why <entry.js> <contributor.js> would make a report starting at contributor.js that shows how many bytes it is, how many bytes it transitively imports, and how many bytes it transitively imports that were not accounted for by previous entries, then indent (maybe) and make the same report for each of its shallow imports from largest differential weight to least.

The tool will need to take the same -C,condition as bundle-source.

  • take a bundle
  • list the non-compartment-map files in the bundle
  • for a given file, display the retention path(s) from the entry module in the compartment map:
  • by reading the compartment map,
  • for each concrete module in the compartment map, depending on the type of the module, extract the import specifiers of that module
  • and use the resolve function compartment-mapper/src/node-module-specifier.js to turn each import specifier into a package-relative specifier, then join the compartment location to get a fully qualified path in the zip file of both the importer and importee,
  • follow the full import specifier through the compartment map to the file name of the physical dependency,
  • emit an edge for each importer -> importee
  • create a multimap Map<string, Set<string>> for the inverse dependency graph
  • print a trace by walking that “cograph” from the file in question to the entry point in the compartment map

Security Considerations

None.

Scaling Considerations

None.

Test Plan

None.

Compatibility Considerations

None.

Upgrade Considerations

None.

kriskowal avatar Aug 16 '24 00:08 kriskowal

Maybe trace-imports

kriskowal avatar Aug 16 '24 00:08 kriskowal

See also https://github.com/Agoric/agoric-sdk/issues/9900 and the nice collections of links it cites

erights avatar Aug 16 '24 19:08 erights