News for hackers. Stuff that matters.
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.