codemod-com / codemod

The end-to-end platform for creating, sharing, and running codemods with engines like jscodeshift, ast-grep, ts-morph, and more. Automate code migrations, cleanups, and refactors for you, your team, and the community. AI-powered and CLI-first.
https://go.codemod.com/docs
Apache License 2.0
345 stars 30 forks source link

[studio] before/after editor performance is severely degraded with many lines of code #1272

Open with-heart opened 3 weeks ago

with-heart commented 3 weeks ago

Issue Description

Select one of: [ ] Generated codemod is not correct [ ] Bug in Codemod Studio [x] UI/UX improvement request [ ] Feature request

In a Before/After editor with thousands of lines of code, I'm experiencing ~1s of lag for each character input and when blurring the editor.

Steps to Reproduce

In the before/after editor

  1. Add thousands of lines of code
  2. Attempt to type input and notice lag
  3. Blur the editor by switching to another panel and notice lag

Actual Results

Lag!

Expected Results

No lag!

Technical details

Export-1724284382458

Browser: Arc 1.56.0 (52658) in incognito mode Device: MacBook Pro M1 Max, Sonoma 14.6.1

alexbit-codemod commented 3 weeks ago

great catch. this happens when that code is parsable. if its not parsable there is no lag... so i guess its something related to that.... maybe on each keystroke we parse the whole tree? will look into it later and consider it as low pri for now.

curious, how did you come across this? like why do you put so much code in before/after? did you come here via codemod learn command?

alexbit-codemod commented 3 weeks ago

even for rust-based parsers and ast-grep playground this problem appears.

with-heart commented 3 weeks ago

curious, how did you come across this? like why do you put so much code in before/after? did you come here via codemod learn command?

Yeap, codemod learn on an xstate test file.

There are a few different variations of a change I'm wanting to make to the tests so I converted that whole file by hand and then ran it.

It kinda sucks that so much of the file was included in the editor just because I changed a single import. The second change wasn't until somewhere around line 1800 I think but all of the text in between them was included.

alexbit-codemod commented 3 weeks ago

yeah. i wonder how we can improve codemod learn so it only extract relevant stuff to build the codemod or populate that in codemod studio.... i run this by the team to see if we can come up with some ideas. but if you have some, please share that with us.