-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3268 from quantified-uncertainty/profiler
Profiler
- Loading branch information
Showing
44 changed files
with
1,095 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@quri/squiggle-lang": patch | ||
"@quri/squiggle-components": patch | ||
--- | ||
|
||
Profiler mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@quri/squiggle-lang": patch | ||
"@quri/squiggle-components": patch | ||
--- | ||
|
||
Normalized AST serialization - significantly reduces the produced bundle size, in some cases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ node_modules | |
/.vscode/settings.json | ||
.turbo | ||
*.tsbuildinfo | ||
|
||
*.tgz |
58 changes: 58 additions & 0 deletions
58
packages/components/src/components/CodeEditor/profilerExtension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { RangeSet, RangeSetBuilder } from "@codemirror/state"; | ||
import { Decoration, EditorView } from "@codemirror/view"; | ||
|
||
import { simulationField } from "./fields.js"; | ||
|
||
const makeMark = (intensity: number) => { | ||
const min = 100; | ||
const color = 255 - min + min * (1 - intensity); | ||
return Decoration.mark({ | ||
attributes: { | ||
style: `background-color: rgb(255,${color},${color},50%)`, | ||
}, | ||
}); | ||
}; | ||
|
||
export function profilerExtension() { | ||
const empty = RangeSet.of<Decoration>([]); | ||
|
||
const decorations = EditorView.decorations.compute( | ||
["doc", simulationField.field], | ||
(state) => { | ||
const simulation = state.field(simulationField.field); | ||
if (!simulation) { | ||
return empty; | ||
} | ||
|
||
if (simulation.code !== state.doc.toString()) { | ||
return empty; | ||
} | ||
|
||
const { output } = simulation; | ||
if (!output.ok) { | ||
return empty; | ||
} | ||
|
||
const profile = output.value.raw.runOutput.profile; | ||
if (!profile) { | ||
return empty; | ||
} | ||
|
||
const times = profile.times; | ||
const totalTimes = times.reduce((a, b) => a + b, 0); | ||
const scaledTimes = times.map((t) => t / totalTimes); | ||
const maxTime = Math.max(...scaledTimes); | ||
const normalizedTimes = scaledTimes.map((t) => t / maxTime); | ||
|
||
const builder = new RangeSetBuilder<Decoration>(); | ||
const docString = state.doc.toString(); | ||
for (let pos = 0; pos < docString.length; pos++) { | ||
const mark = makeMark(normalizedTimes[pos]); | ||
builder.add(pos, pos + 1, mark); | ||
} | ||
return builder.finish(); | ||
} | ||
); | ||
|
||
return [decorations]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const infixFunctions = { | ||
"+": "add", | ||
"-": "subtract", | ||
"!=": "unequal", | ||
".-": "Dist.dotSubtract", | ||
".*": "Dist.dotMultiply", | ||
"./": "Dist.dotDivide", | ||
".^": "Dist.dotPow", | ||
".+": "Dist.dotAdd", | ||
"*": "multiply", | ||
"/": "divide", | ||
"&&": "and", | ||
"^": "pow", // or xor | ||
"<": "smaller", | ||
"<=": "smallerEq", | ||
"==": "equal", | ||
">": "larger", | ||
">=": "largerEq", | ||
"||": "or", | ||
to: "to", | ||
}; | ||
|
||
export const unaryFunctions = { | ||
"-": "unaryMinus", | ||
"!": "not", | ||
".-": "unaryDotMinus", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.