Skip to content

Conversation

unlessgames
Copy link
Collaborator

A feature that is present on many livecoding sites, encoding the script you write into the URL hash using a base64 string as you type, so that it is easy to share a script by simply copy-pasting the link.

Wrapping the script into an object here so that created links stay future proof in case we want to add encoding more states like the default sample, parameter values or something else besides the script string later.

Overall, not the most elegant thing but it proved useful on other sites like this and it is easy to implement.

Copy link

github-actions bot commented Oct 9, 2025

Benchmark for 33728b4

Click to view benchmark
Test Base PR %
Cycle/Generate 48.7±0.69µs 48.5±0.48µs -0.41%
Cycle/Parse 378.7±6.65µs 381.7±6.98µs +0.79%
Rust Phrase/Clone 431.5±5.78ns 426.8±6.02ns -1.09%
Rust Phrase/Create 76.8±1.23µs 77.0±3.68µs +0.26%
Rust Phrase/Run 661.1±10.88µs 657.5±3.06µs -0.54%
Rust Phrase/Seek 144.8±267.99µs 136.8±253.03µs -5.52%
Scripted Phrase/Clone 660.4±6.81ns 654.8±7.67ns -0.85%
Scripted Phrase/Create 993.9±13.08µs 996.4±22.49µs +0.25%
Scripted Phrase/Run 1700.4±15.62µs 1698.8±15.82µs -0.09%
Scripted Phrase/Seek 241.3±492.67µs 228.6±463.67µs -5.26%

@emuell
Copy link
Member

emuell commented Oct 10, 2025

This is definitely a great little thing to have!

I see it's getting complicated to track what caused the script change. Also, when loading a URL with a hash I see the correct hashed script in the editor but when starting to play it's playing back the default script. So there's a backend.updateScriptContent(someContent); missing somewhere.

Also wondering if the hash should only update when committing and not while editing. That might make change tracking easier, too.

Copy link

Benchmark for 47b3123

Click to view benchmark
Test Base PR %
Cycle/Generate 48.7±0.96µs 48.7±0.83µs 0.00%
Cycle/Parse 378.4±8.15µs 377.9±8.51µs -0.13%
Rust Phrase/Clone 439.6±7.14ns 424.2±5.90ns -3.50%
Rust Phrase/Create 76.0±1.55µs 75.6±0.75µs -0.53%
Rust Phrase/Run 661.4±5.07µs 659.1±8.45µs -0.35%
Rust Phrase/Seek 144.1±272.25µs 141.9±261.20µs -1.53%
Scripted Phrase/Clone 647.5±5.86ns 651.0±8.14ns +0.54%
Scripted Phrase/Create 1001.5±19.98µs 985.2±15.29µs -1.63%
Scripted Phrase/Run 1694.2±25.48µs 1708.3±27.82µs +0.83%
Scripted Phrase/Seek 235.5±471.52µs 243.3±469.65µs +3.31%

@unlessgames
Copy link
Collaborator Author

Fixed the issues.

I think it's better to update the hash on all edits, the change needs to be tracked in both cases the same way unfortunately and to me it feels more straightforward if the hash simply mirrors whatever is in the editor at any moment, but it is easy to move this into the commit action if you want.

Copy link

Benchmark for fa2825b

Click to view benchmark
Test Base PR %
Cycle/Generate 48.2±0.76µs 48.3±0.52µs +0.21%
Cycle/Parse 373.3±4.82µs 380.5±7.42µs +1.93%
Rust Phrase/Clone 439.4±6.78ns 428.6±6.04ns -2.46%
Rust Phrase/Create 76.4±1.58µs 77.0±1.08µs +0.79%
Rust Phrase/Run 660.2±9.24µs 663.2±6.73µs +0.45%
Rust Phrase/Seek 139.1±257.03µs 141.9±267.13µs +2.01%
Scripted Phrase/Clone 654.8±8.99ns 652.5±9.99ns -0.35%
Scripted Phrase/Create 992.7±19.72µs 1002.3±25.83µs +0.97%
Scripted Phrase/Run 1716.1±47.15µs 1700.0±15.57µs -0.94%
Scripted Phrase/Seek 231.6±467.39µs 233.4±472.70µs +0.78%

@emuell emuell changed the base branch from master to dev October 10, 2025 13:13
@emuell
Copy link
Member

emuell commented Oct 10, 2025

That works great. I'd rebase this on dev and merge this as it is then. Or would you like to add something else here?

@unlessgames
Copy link
Collaborator Author

I made it load the instrument from the hash as well, this way shared scripts might make more sense (we could also assign default instruments for the examples for variety).

Also made the playback button a toggle, this saves space and better aligns with the editor shortcut (added a hint for that to the button tooltip). Tweaked the style a bit so that buttons change in look when pressed (before this, the hover and pressed styles were the same).

Changed some of the style manipulation to toggling classes and descibing them in the css.

Colored the scrollbar and toned down the list markers for a better look.

Apologies for the additional changes squeezed into this PR but as touching this part is not much fun, it seemed best to implement these other improvements while I was at it.


Btw, should I push the built wasm and minified .js files? These feel like they shouldn't be in version control.

@unlessgames unlessgames marked this pull request as ready for review October 10, 2025 20:06
@emuell emuell force-pushed the playground/script-hash branch from d533d04 to 08a0465 Compare October 10, 2025 20:31
@emuell
Copy link
Member

emuell commented Oct 10, 2025

Looks great and works, so I'm of course fine with it :)

Btw, should I push the built wasm and minified .js files? These feel like they shouldn't be in version control.

I had added them to make it easier to test things locally. As the playground is hosted online, this no longer is necessary. I'll remove them...

The app.js changes do not affect the playground.* files. Those only need to be rebuilt when the rust backend code or asset data changes. Likely they show up modified in your case, because you are using a different emscripten compiler version than I did when committing the files...

@emuell emuell merged commit ba7391e into dev Oct 10, 2025
@emuell emuell deleted the playground/script-hash branch October 10, 2025 20:37
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.

2 participants