News for hackers. Stuff that matters.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by artursapek on Thursday March 23, 2017 @11:17AM (#13940458)
I'm reminded of this classic: https://github.com/npm/npm/issues/11283

NPM had a progress bar that was so fancy that it slowed down installation time (basically its only job) by ~50%. Hilarious.

My mantra here is, if you find yourself thinking about implementing a fancy loading spinner/progress bar, it would be more productive to just spend that time making it unnecessary - speed up your shit! Obviously that doesn't apply to VS Code's cursor.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by peckrob on Thursday March 23, 2017 @02:17PM (#13942501)
This reminds me of one of my favorite old tech stories.

A long while back (seems like this was the late 90s or early 2000s) I was working on a script that did some data processing on a remote machine. It had to loop through a bunch of text log data and generate some reports. Being as that I had no idea if the script was actually working until it completed awhile later, I decided to put in a neat little ASCII spinner in it when you ran it with verbose options.

At the time I was on a slow dialup connection as I was on break from school, and something weird would happen. Every time I ran the script to test it, my Internet connection would become nearly unusable. But as soon as the script finished, it would suddenly start working again.

As you can imagine, this was very confusing since the script was running entirely on a remote system. What the hell is going on?

This stumped me for an hour or so until I ran it without the verbose option ... and it didn't happen. Then I finally realized what was happening: I was refreshing the spinner on EACH ROW and remote machine was going through the rows so quickly that sending refreshes for the spinner saturated my tiny dial-up connection. Changing this to only update once a second fixed it entirely.

And that's how I DoS'd myself with a spinner.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by flukus on Thursday March 23, 2017 @07:58PM (#13945458)
I've got a similar one. I was working on an app once where the current results were being logged to a text box, nothing too fancy, but I noticed it got a lot slower on larger blocks. Changing "textBox.Text = textBox.Text + newline" to "textBox.Append(newLine)" cut >99% of the CPU time.

On the same project I discovered that "System.Envireonment.NewLine" was a relatively expensive call on c#, caching the result of that property was another 50% cut to CPU.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by kelvin0 on Thursday March 23, 2017 @02:40PM (#13942754)
Nice foot gun story. If you had a T1 at the time, you would never had noticed such a pitfall.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by agumonkey on Thursday March 23, 2017 @04:23PM (#13943891)
I often advise to write code on "obsolete" tech. It makes every bit of cruft obvious.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by kuschku on Sunday March 26, 2017 @01:32PM (#13961889)
I test all of my apps on an old Moto G, second generation, on throttled mobile internet (64kbps).

That’s the average worst case user.

This also means I notice massively if an app has hardcoded timeouts, or loads massive amounts of data.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by peckrob on Thursday March 23, 2017 @02:58PM (#13942981)
Pretty much, yeah. I never noticed it on campus because I was sitting on a 10 megabit connection.

That added an extra dimension to the confusion because I was sure this never happened when I was on campus, only when I was sitting 300 miles away. It was still happening if I had bothered to look at the network stats, just not enough to entirely saturate the connection.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by androbabu on Tuesday April 04, 2017 @07:02PM (#14038080)
Your story reminds me a current scenario @peckrob ..

For Android Application development, we used to connect devices to computer via usb and would see the device's log in logcat tool (Android Studio). The device, in general, spawns lots of logcat messages during a debugging session and would eats up CPU.

The case is still worse that the tool stucks when device is connected over wifi (wifi-adb) as the data transfer is little lower in wifi than usb.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by jcwayne on Thursday March 23, 2017 @01:20PM (#13941827)
In the early days of working on my current main project, I found that updating a progress bar was slowing the process it was monitoring. Since there were times when it was useful to see near real-time progress, I added added a slider which allows the user to adjust the sampling rate. That slider is affectionately known (by me anyway) as the Heisenberg Compensator.

P.S. I have sped up my shit. That process originally took days, now it takes an hour.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by maccard on Thursday March 23, 2017 @05:55PM (#13944722)
It's fairly regular in my field (game dev) to put some debugging/instrumentation code in and only enable it for one frame after a key is pressed.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by m-p-3 on Thursday March 23, 2017 @02:40PM (#13942758)
> Heisenberg Compensator

That's a perfect name, I love it.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by fapjacks on Thursday March 23, 2017 @07:29PM (#13945310)
There's a Heisenberg Compensator in Star Trek transporters [0]

[0] http://www.startrek.com/database_article/heisenberg-compensa...

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by jcwayne on Thursday March 23, 2017 @10:07PM (#13946003)
Not​ a coincidence.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Zenst on Thursday March 23, 2017 @01:45PM (#13942117)
IBM spent a humongous amount of man hours upon the running man in smit under AIX, many of those consumed with making sure it ran correctly on all systems of various speeds without the animations going crazy. Alas I don't have exact man hours, but that was what one of the engineers told me a nearly 2 decades ago now. Hopefully somebody else has more detail upon this as one of the earliest examples of progress animations that still runs today that I'm aware of.

I still hark back to the days of the C64 and the likes in which had tape storage and was common to have a game as a loading screen to play. Was a small program and used to give the user something to do whilst they waited 20 minutes for the program to load. Many also rewrote the cassette storage code for faster storage/loading and would often be a case of loading that program with the small game like space invaders that you could play whilst the main game loaded utilising the quicker tape handling code.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by eltoozero on Thursday March 23, 2017 @03:01PM (#13943025)
SMIT running man example: https://www.youtube.com/watch?v=YMWSD69BWqI

If anyone knows where I can get those animation frames, I'd like them for a personal project as a "running" indicator.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by _sh on Friday March 24, 2017 @12:46AM (#13946669)
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by krylon on Thursday March 23, 2017 @02:20PM (#13942532)
Broken Sword let you play Breakout during the installation; it was such fun (I had not played Breakout in a long time at the point) I was almost sad when the installation was finished. ;-)

I have often wondered since why this was not a more popular way to deal with long running installers.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by aerique on Thursday March 23, 2017 @02:55PM (#13942939)
I think it's because Namco had a patent on games in loading screens from 1995 to 2015: http://kotaku.com/the-patent-on-loading-screen-mini-games-is...
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by reitanqild on Thursday March 23, 2017 @07:34PM (#13945333)
Ghostbusters game on c64 had it when I bought it used in 1991 or 92 I think.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by yoklov on Friday March 24, 2017 @11:42AM (#13949652)
It's a common example for a patent that had a lot of prior art but was granted anyway.

I don't know enough about patents to say if there was a reason the prior art didn't apply, but I know that Namco was fairly protective of it and it was somewhat limiting for people working in the game industry.

Although, loading screens are less common now than they were back then, and I think that would still be case even if such a thing were never patented.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by royjacobs on Thursday March 23, 2017 @02:45PM (#13942817)
Having minigames during loading or installation was actually patented by Namco for Ridge Racer, I believe. I'm not quite sure about the details since I seem to recall things like invade-a-load on my Commodore 64 at least a decade earlier, but there you go.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Cpoll on Thursday March 23, 2017 @02:51PM (#13942902)
Expired in 2015 :)

When I was younger, it seemed so obvious to add a minigame to a long loading screen, I had assumed that there were technical reasons for not doing it.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by dEnigma on Sunday March 26, 2017 @01:39PM (#13961936)
Not quite the same thing, but DVDFlick lets you play Tetris while your DVD is being authored and burned, which was a nice suprise.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by michel-slm on Thursday March 23, 2017 @04:14PM (#13943803)
One Linux distribution used to let you play Breakout during installation, but I forgot which one. Caldera, maybe?
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by eru on Sunday March 26, 2017 @04:25PM (#13963051)
Don't most Linux installation just let you use your computer normally during installation?

(And by normally I mean, as booted from a LiveCD.)

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Touche on Thursday March 23, 2017 @11:24AM (#13940545)
I think I don't understand the issue well enough. This looks like a standard blinking cursor to me. Users expect a blinking cursor in an editable text field.

I'm not sure why this implementation is slow or why they needed to implement it themselves and not let the OS handle the blinking cursor. I'm guessing there must be some reason.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by paulirish on Thursday March 23, 2017 @12:30PM (#13941293)
Powerful* text editors built on the web stack cannot rely on the OS text caret and have to provide their own.

In this case, VSCode is probably using the most reasonable approach to blinking a cursor: a `step` timing-function with a CSS keyframe animation. This tells the browser to only change the opacity every 500ms. Meanwhile, Chrome hasn't yet optimised this completely yet, hence http://crbug.com/361587.

So currently, Chrome is doing the full rendering lifecycle (style, paint, layers) every 16ms when it should be only doing that work at a 500ms interval. I'm confident that the engineers working on Chrome's style components can sort this out, but it'll take a little bit of work. I think the added visibility on this topic will likely escalate the priority of the fix. :)

* Simple text editors, and basic ones built on [contenteditable] can, but those rarely scale to the feature set most want.

(I work on the Chrome team, though not on the rendering engine)

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Someone on Thursday March 23, 2017 @05:41PM (#13944628)
"So currently, Chrome is doing the full rendering lifecycle (style, paint, layers) every 16ms when it should be only doing that work at a 500ms interval"

Only? It shouldn't be necessary to layout the entire window to redraw a cursor.

Also, if it did update every 500ms:

- it still would use about half a percent of CPU. On a machine whose CPU easily is >200 times as fast as those powering the first GUIs (and those _could_ blink the caret at less than 100% CPU) and that has a powerful GPU, that's bad (yes, those old-hat systems had far fewer pixels to update, but that's not a good excuse)

- implementing smoother blinking (rendering various shades of gray in-between) would mean going back to 13% CPU.

I would try and hack this by layering an empty textfield on top of the content, just to get a blinking caret. Or is it too hard to make that the right size and position it correctly?

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Mister_Snuggles on Thursday March 23, 2017 @02:49PM (#13942862)
> Powerful* text editors built on the web stack cannot rely on the OS text caret and have to provide their own.

Is there any reason that Electron couldn't provide an API that would expose the system caret in an OS-agnostic manner? Windows, for example, has an API[0] that can arbitrarily show the caret at a given point in the window. Sounds like something that would be useful to many apps and not get in the way for those that don't need it.

[0] https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by mohaine on Thursday March 23, 2017 @03:54PM (#13943594)
Probably not easily. Remember this is what java AWT did and it was a complete mess. Write once debug everywhere.

My favorite issues was that on one OS (windows I think) a panel would only be visible if pixel 0,0 was on the screen and nothing was on top of it. The panel could be 99% visible but not be shown at all if the upper left corner was under another panel.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by pcwalton on Thursday March 23, 2017 @01:19PM (#13941814)
Why are you even painting at all instead of layerizing it?

(This is a perfect example of what I've been increasingly convinced of lately: that the whole "paint"/"compositing" distinction hurts the Web…)

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by biggiesmalls on Thursday March 23, 2017 @07:20PM (#13945253)
>> text editors built on the web stack cannot rely on the OS text caret

Can you explain in simple terms why this is the case? Why on earth not?

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Sharlin on Friday March 24, 2017 @02:25AM (#13947080)
Because you can't just ask the OS to "please paint text caret here thankyou", and browsers do not expose a powerful enough native text editing control. So you end up reimplementing one in JS/HTML/CSS, including the caret.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by heinrich5991 on Sunday March 26, 2017 @07:54PM (#13964111)
The WinAPI function SetCaretPos seems to do that: https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by prafuitu on Thursday April 06, 2017 @08:02AM (#14049771)
Well, because, in order to satisfy the most finicky of its users (myself included), VS Code offers no less than 6 styles for its cursor ('block', 'block-outline', 'line', 'line-thin', 'underline' and 'underline-thin') and 5 animations ('blink', 'smooth', 'phase', 'expand' and 'solid'). Also, in a future release the themes will be allowed to change the color of the cursor to any of the 16,581,375 colors in the RGB spectrum.

Does that answer your question? :)

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Kristine1975 on Thursday March 23, 2017 @01:19PM (#13941811)
>http://crbug.com/361587

Reported almost 3 years ago and still not fixed...

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by nolok on Thursday March 23, 2017 @11:31AM (#13940618)
> I'm not sure why this implementation is slow

I'm guessing the culprit for that is in this part of the bug report:

> Zooming into a single frame, we see that while we render only 2 fps, the main thread is performing some work at 60 fps (every 16 ms)

As for

> why they needed to implement it themselves and not let the OS handle the blinking cursor

They're not editing inside a text editor field anymore, they need to blink on html. I guess they're not using a deprecated <blink> tag is because it's not customizable in any way.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by kibwen on Thursday March 23, 2017 @12:17PM (#13941161)
I don't believe that any modern browser still supports the blink tag; IIRC Firefox was the last to get rid of it, a year or two ago. You can hack it up in CSS, though.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by ethbro on Thursday March 23, 2017 @03:07PM (#13943084)
Truly, the web has come full circle.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Mister_Snuggles on Thursday March 23, 2017 @03:05PM (#13943061)
On Win32[0], the blinking caret can be shown anywhere inside a window, not just on a text field. The sample program builds a basic text editor without cheating and using a textbox control.

I'm sure other operating systems have this kind of facility - after all, how does the built in text edit control draw its caret?

[0] https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by coldtea on Thursday March 23, 2017 @03:50PM (#13943544)
>On Win32[0], the blinking caret can be shown anywhere inside a window, not just on a text field. (...) I'm sure other operating systems have this kind of facility - after all, how does the built in text edit control draw its caret?

The "built in text edit control" IS a native text field already.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Mister_Snuggles on Thursday March 23, 2017 @03:58PM (#13943647)
My point is that the built-in text edit control needs some way to draw it's caret, so surely a universal method to draw a blinking caret exists somewhere.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by coldtea on Thursday March 23, 2017 @04:35PM (#13944004)
Well, they could just make a C extension to Electron that draws a blinking colored line (that's all it is) using the OSes arbitrary drawing facilities.

No need to have an official OS caret function (especially if you're not a native text field, and caret aside, the rest of your text editing will be different/broken in subtle ways compared to the OS).

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Someone on Thursday March 23, 2017 @05:52PM (#13944704)
I'm not aware of any system where one can create that caret without a text edit control to hold it. That means that, if the standard text edit control isn't suited for what you want to do, you can't have the caret.

Certainly, on the original Mac OS (a system on which I worked on OS patches for detecting the location of the caret) the method that application used for drawing the caret varied widely. I've seen it implemented by drawing a line, by drawing a rectangle, either in one go or in two parts (that happened in applications that supported a split caret, even if the caret wasn't split), with various transfer modes. Slanted carets typically were application-specific, too.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Mister_Snuggles on Thursday March 23, 2017 @06:40PM (#13945003)
> I'm not aware of any system where one can create that caret without a text edit control to hold it.

Windows allows this. In a parent comment I posted a link to the API docs. All Windows requires is a window to hold the caret, it doesn't care what kind of window it is.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by Touche on Thursday March 23, 2017 @12:17PM (#13941164)
Thanks, so they are probably not using a contenteditable element. In that case it makes sense that they would need to use a CSS animation to blink the cursor.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by azrazalea on Thursday March 23, 2017 @11:31AM (#13940627)
> why they needed to implement it themselves and not let the OS handle the blinking cursor.

Probably because they are using electron.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by billconan on Thursday March 23, 2017 @12:04PM (#13941002)
this is exactly the same problem I met yesterday.

I made a webpage based on a bootstrap template

On this webpage, I have 2 realtime components. one is a chart, based on dygraphs

the other component is a bootstrap progressbar.

the bootstrap progressbar is made by html divs:

https://www.w3schools.com/Bootstrap/bootstrap_progressbars.a...

Both components are updated in realtime by a websocket.

I noticed that the chart by itself is very fast. But as soon as the progressbar is added, the entire webpage and even the entire machine becomes very slow. I guess this is because every bit of progressbar update, the browser rerender the entire page, as the progressbar is a div.

I don't know how to solve this. I thought about using react for its virtual dom. but if eventually I need to update the dom, the speed seems to be the same.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by scriptproof on Thursday March 23, 2017 @12:37PM (#13941367)
There is an HTML 5 progress tag supported by all browsers: <progress id="" max=100>
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by jinglebells on Thursday March 23, 2017 @03:59PM (#13943656)
Can you buffer the incoming websockets data and only update at a small percentage of the inputs or maybe based on time?

Lodash has a debounce function which is useful to throttle UI features hooked to incoming data. https://css-tricks.com/debouncing-throttling-explained-examp...

You never really want the UI repaint to be dictated by data, it's better to use timers.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by fegu on Thursday March 23, 2017 @05:01PM (#13944229)
Am I the only one around here who prefers a nonblinking cursor. That and key repeat rate are my first setting on any new install.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by tmsldd on Thursday March 23, 2017 @04:52PM (#13944142)
Minimizing the installation window would prevent the paint event and your installation would finish quickly...
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by tinus_hn on Thursday March 23, 2017 @11:29AM (#13940597)
iTunes has the same issue with its spinner while syncing, it takes about 20% CPU time.
Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by coldtea on Thursday March 23, 2017 @03:51PM (#13943561)
Who said it's the spinner in that case?

After all, it IS syncing at that time, which means it does a lot of stuff.

Whereas the issue here is with the caret shown when the editor is idle.

Re:VS Code uses 13% CPU when idle due to blinking cursor ren... by tinus_hn on Friday March 24, 2017 @10:54AM (#13949277)
Activity Monitor allows you to easily profile what the application is spending its CPU time on and it shows that iTunes spends an excessive amount of its time on updating the UI, specifically the spinner.