Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add command to render multiple trios in roger #1471

Merged
merged 3 commits into from Jun 9, 2023
Merged

Conversation

wodeni
Copy link
Member

@wodeni wodeni commented Jun 8, 2023

Description

Resolves #1439.

This PR contains 2 strategies to mitigate the roger startup time, which is mostly caused by the node runtime.

  1. Switch from tsx to ts-node --esm --swc because we observed a 40% speedup when using ts-node. This will hopefully reduce the cost of a single roger run.
  2. Add roger trios [trios..] -o <output-path> to support batch-rendering multiple trios. This command expects a list of .trio.json files (the extension is necessary for accurate guessing of the output svg file) and render them to <output-path.

A small thing: ts-node prints out a warning for our package.json import for version printing (see issue). This is a Node problem, but I've disabled roger --version for now to avoid the noisy output.

Examples with steps to reproduce them

In packages/examples, run roger trios **/*.trio.json -o out to render all the trios!

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have reviewed any generated registry diagram changes

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jun 8, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9c337af
Status: ✅  Deploy successful!
Preview URL: https://315ef768.penrose-72l.pages.dev
Branch Preview URL: https://roger-fast.penrose-72l.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Jun 8, 2023

± Registry diff

📊 Performance

Key

Note that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.

     0s   1s   2s   3s   4s   5s   6s   7s   8s
     |    |    |    |    |    |    |    |    |
name ▝▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▞▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▖
      compiling labeling optimizing rendering

If a row has only one bar instead of four, that means it's not a trio and the bar just shows the total time spent for that example, again rounded up to the nearest 100ms.

Data

                                                          0s   1s   2s   3s   4s   5s
                                                          |    |    |    |    |    |
set-theory-domain/tree-venn                               ▝▀▞▖
set-theory-domain/tree-tree                               ▝▀▞▖
set-theory-domain/tree-venn-3d                            ▝▚▚▖
group-theory/quaternion-multiplication-table              ▝▀▀▄▚▖
group-theory/quaternion-cayley-graph                      ▝▀▞▖
atoms-and-bonds/wet-floor                                 ▝▚▀▀▚
atoms-and-bonds/one-water-molecule                        ▝▞▖
set-theory-domain/continuousmap                           ▝▞▖
linear-algebra-domain/two-vectors-perp                    ▝▚▚
molecules/nitricacid-lewis                                ▝▀▀▞▀▖
exterior-algebra/vector-wedge                             ▝▞▖
shape-spec/all-shapes                                     ▝▞▄▄▄
shape-spec/arrowheads                                     ▝▞▖
graph-domain/textbook/sec1/fig1                           ▝▀▀▞▚
graph-domain/textbook/sec1/fig2                           ▝▀▀▚▀▚
graph-domain/textbook/sec1/fig3                           ▝▀▀▀▞▀▚
graph-domain/textbook/sec1/fig4                           ▝▀▀▀▚▀▀▖
graph-domain/textbook/sec1/fig5                           ▝▀▀▀▀▞▀▀▀▖
graph-domain/textbook/sec1/fig6                           ▝▀▀▀▀▀▀▀▀▀▞▀▀▀▀▀▀▀▀▀▀▀▀▀▚
graph-domain/textbook/sec1/fig7                           ▝▀▀▞▚
graph-domain/textbook/sec1/fig8a                          ▝▀▀▀▀▞▀▀▖
graph-domain/textbook/sec1/fig8b                          ▝▀▀▚▀▀▚
graph-domain/textbook/sec1/fig9                           ▝▀▀▞▚
graph-domain/textbook/sec1/fig10                          ▝▀▚▚▖
graph-domain/textbook/sec1/fig11                          ▝▀▀▚▀▄
graph-domain/textbook/sec1/fig12                          ▝▀▀▀▚▀▀▄
graph-domain/textbook/sec1/fig13                          ▝▀▀▚▀▀▖
graph-domain/textbook/sec2/fig3                           ▝▀▀▀▀▀▚▀▀▀▀▚
graph-domain/textbook/sec2/fig4                           ▝▀▀▀▚▀▀▚
graph-domain/textbook/sec2/fig5                           ▝▀▀▀▀▀▀▞▀▀▀▚
graph-domain/textbook/sec2/fig6                           ▝▀▀▀▀▀▚▀▀▀▚
graph-domain/textbook/sec2/fig9                           ▝▀▀▀▀▀▀▀▀▀▚▀▀▀▀▀▀▚
graph-domain/textbook/sec2/fig10a                         ▝▀▚▀▚
graph-domain/textbook/sec2/fig10b                         ▝▀▀▞▚
graph-domain/textbook/sec2/fig11a                         ▝▀▞▖
graph-domain/textbook/sec2/fig11b                         ▝▚▚
graph-domain/textbook/sec2/fig11c                         ▝▀▞▖
graph-domain/textbook/sec2/fig12                          ▝▀▞▖
graph-domain/textbook/sec2/fig13                          ▝▀▀▀▀▀▀▀▀▀▞▀▀▀▀▀▀▀▀▀▖
graph-domain/textbook/sec2/fig14                          ▝▀▀▚▚▖
graph-domain/textbook/sec2/fig16b                         ▝▀▀▞▖
geometry-domain/textbook_problems/c05p13                  ▝▀▞▖
geometry-domain/textbook_problems/c01p01                  ▝▀▞▖
geometry-domain/textbook_problems/c03p01                  ▝▀▞▖
geometry-domain/textbook_problems/c05p01                  ▝▀▞▖
geometry-domain/textbook_problems/ex                      ▝▀▀▞▚
triangle-mesh-3d/two-triangles                            ▝▚▚
random-sampling/test                                      ▝▀▀▚▚
geometry-domain/textbook_problems/c11p12                  ▝▀▞▖
word-cloud/example                                        ▝▚▚
geometry-domain/siggraph-teaser                           ▝▀▚▚
minkowski-tests/maze/non-convex                           ▝▚▚
lagrange-bases/lagrange-bases                             ▝▞▖
hypergraph/hypergraph                                     ▝▀▀▚▀▀▀▀▀▀▀▀▖
persistent-homology/persistent-homology                   ▝▀▚▀▀▀▀▀▄
walk-on-spheres/laplace-estimator                         ▝▀▞▖
walk-on-spheres/poisson-estimator                         ▝▀▞▀▚
walk-on-spheres/nested-estimator                          ▝▀▚▀▚
walk-on-spheres/offcenter-estimator                       ▝▀▞▀▚
shape-distance/points-around-star                         ▝▀▀▚▚▖
shape-distance/points-around-polyline                     ▝▀▚▚
shape-distance/points-around-line                         ▝▀▞▖
shape-distance/lines-around-rect                          ▝▞▖
fake-3d-linear-algebra/projection                         ▝▞▖
animation/center-shrink-circle                            ▝▞▖
structural-formula/molecules/caffeine                     ▝▀▚▀▄
mobius/mobius                                             ▝▞▖
molecules/glutamine                                       ▝▀▞▖
matrix-ops/tests/matrix-matrix-addition                   ▝▚▚
matrix-ops/tests/matrix-matrix-division-elementwise       ▝▚▚
matrix-ops/tests/matrix-matrix-multiplication-elementwise ▝▚▚
matrix-ops/tests/matrix-matrix-multiplication             ▝▚▚
matrix-ops/tests/matrix-matrix-subtraction                ▝▚▚
matrix-ops/tests/matrix-transpose                         ▝▚▚
matrix-ops/tests/matrix-vector-left-multiplication        ▝▚▚
matrix-ops/tests/matrix-vector-right-multiplication       ▝▚▚
matrix-ops/tests/scalar-vector-division                   ▝▚▚
matrix-ops/tests/scalar-vector-left-multiplication        ▝▚▚
matrix-ops/tests/scalar-vector-right-multiplication       ▝▚▚
matrix-ops/tests/vector-vector-addition                   ▝▚▚
matrix-ops/tests/vector-vector-division-elementwise       ▝▚▚
matrix-ops/tests/vector-vector-multiplication-elementwise ▝▀▞▖
matrix-ops/tests/vector-vector-outerproduct               ▝▚▚
matrix-ops/tests/vector-vector-subtraction                ▝▚▚
logic-circuit-domain/half-adder                           ▝▚▚
curve-examples/cubic-bezier                               ▝▚▀▀▖
triangle-mesh-2d/diagrams/cotan-formula                   ▝▀▞▀▖
triangle-mesh-2d/diagrams/concyclic-pair                  ▝▀▞▖
triangle-mesh-2d/diagrams/halfedge-mesh                   ▝▀▞▖
triangle-mesh-2d/diagrams/relative-orientation            ▝▚▚
triangle-mesh-2d/diagrams/triangle-centers                ▝▚▚
triangle-mesh-2d/diagrams/angle-equivalence               ▝▀▚▀▀▖
timeline/penrose                                          ▝▀▚▚
graph-domain/textbook/sec5/ex32                           ▝▀▀▀▀▚▀▀▀▀▀▚
curve-examples/open-elastic-curve                         ▝▀▚▀▖
curve-examples/closed-elastic-curve                       ▝▀▞▀▖
graph-domain/other-examples/arpanet                       ▝▀▀▀▀▀▀▞▀▀▀▀▀▀▀▀▀▀▚
graph-domain/other-examples/nyc-subway                    ▝▀▀▀▀▞▀▀▀▖
curve-examples/blobs                                      ▝▀▀▀▀▀▞▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
curve-examples/space-curves                               ▝▀▀▀▀▀▞▀▀▚
solid/example                                             ▐
geometric-queries/ray-intersect/test-group                ▝▀▀▀▀▀▀▚▚▖
ray-tracing/path-trace                                    ▝▀▀▞▖
ray-tracing/bidirectional                                 ▝▀▚▚
ray-tracing/next-event-estimation                         ▝▀▚▚
geometric-queries/test                                    ▝▀▞▖
geometric-queries/closest-point/test-group                ▝▚▚
geometric-queries/closest-point/test                      ▝▚▚
geometric-queries/closest-silhouette-point/test           ▝▚▚
geometric-queries/ray-intersect/test                      ▝▀▀▀▀▀▀▀▞▄▖

@wodeni wodeni marked this pull request as ready for review June 8, 2023 13:51
@wodeni wodeni requested a review from samestep June 8, 2023 13:51
@samestep
Copy link
Collaborator

samestep commented Jun 8, 2023

You can fix the JSON import with this diff:

diff --git a/packages/roger/index.ts b/packages/roger/index.ts
index 48303f8b..dc7f6bad 100755
--- a/packages/roger/index.ts
+++ b/packages/roger/index.ts
@@ -22,7 +22,7 @@ import convertHrtime from "convert-hrtime";
 import * as fs from "fs";
 import { basename, extname, join, resolve } from "path";
 import prettier from "prettier";
-// import packageJSON from "./package.json"; // TODO: no supported by node
+import packageJSON from "./package.json" assert { type: "json" };
 import { InstanceData } from "./types.js";
 import watch from "./watch.js";
 
@@ -255,7 +255,7 @@ const orderTrio = (unordered: string[]): string[] => {
 yargs(hideBin(process.argv))
   .scriptName("roger")
   // .description("Command-line interface for Penrose.")
-  // .version(packageJSON.version) // TODO: not supported by node
+  .version(packageJSON.version)
   .command(
     "trio [trio..]",
     "Generate a diagram from a Penrose trio.",
diff --git a/packages/roger/tsconfig.json b/packages/roger/tsconfig.json
index 5619f878..246bfc65 100644
--- a/packages/roger/tsconfig.json
+++ b/packages/roger/tsconfig.json
@@ -1,6 +1,7 @@
 {
   "extends": "../../tsconfig.json",
   "compilerOptions": {
+    "module": "ESNext",
     "noEmit": true,
     "noImplicitThis": true,
     "resolveJsonModule": true,

But did you just mean you don't want to do this right now because it causes the following warning?

(node:74017) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Copy link
Collaborator

@samestep samestep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me other than one minor thing, thanks so much Nimo! 🏎️

packages/roger/index.ts Outdated Show resolved Hide resolved
Co-authored-by: Sam Estep <sam@samestep.com>
@wodeni
Copy link
Member Author

wodeni commented Jun 8, 2023

You can fix the JSON import with this diff:

diff --git a/packages/roger/index.ts b/packages/roger/index.ts
index 48303f8b..dc7f6bad 100755
--- a/packages/roger/index.ts
+++ b/packages/roger/index.ts
@@ -22,7 +22,7 @@ import convertHrtime from "convert-hrtime";
 import * as fs from "fs";
 import { basename, extname, join, resolve } from "path";
 import prettier from "prettier";
-// import packageJSON from "./package.json"; // TODO: no supported by node
+import packageJSON from "./package.json" assert { type: "json" };
 import { InstanceData } from "./types.js";
 import watch from "./watch.js";
 
@@ -255,7 +255,7 @@ const orderTrio = (unordered: string[]): string[] => {
 yargs(hideBin(process.argv))
   .scriptName("roger")
   // .description("Command-line interface for Penrose.")
-  // .version(packageJSON.version) // TODO: not supported by node
+  .version(packageJSON.version)
   .command(
     "trio [trio..]",
     "Generate a diagram from a Penrose trio.",
diff --git a/packages/roger/tsconfig.json b/packages/roger/tsconfig.json
index 5619f878..246bfc65 100644
--- a/packages/roger/tsconfig.json
+++ b/packages/roger/tsconfig.json
@@ -1,6 +1,7 @@
 {
   "extends": "../../tsconfig.json",
   "compilerOptions": {
+    "module": "ESNext",
     "noEmit": true,
     "noImplicitThis": true,
     "resolveJsonModule": true,

But did you just mean you don't want to do this right now because it causes the following warning?

(node:74017) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Yep precisely to avoid printing out the warnings

@wodeni wodeni merged commit 9c052fe into main Jun 9, 2023
10 checks passed
@wodeni wodeni deleted the roger-fast branch June 9, 2023 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

roger takes a while to start
2 participants