News for hackers. Stuff that matters.
Re:iTerm2 has a new drawing engine that uses Metal 2 by evmar on Saturday July 28, 2018 @07:13PM (#17635538)
I fiddle in this area as a hobby project. One thing I never understand when I read announcements like this is why the graphics performance affects the throughput. Like in a video game, the world moves at the same rate regardless of the frame rate, so why are the two related here?

In some of my experimental terminal emulators I've decoupled these and it's not so hard -- there's a piece that processes command output as fast as it can, and then there's another piece that updates the screen as fast as it can, and as long as those two pieces are decoupled then even if your graphics hardware is 5fps it's still fast to cat a file.

Re:iTerm2 has a new drawing engine that uses Metal 2 by gnachman on Saturday July 28, 2018 @08:41PM (#17635846)
It's a funny feeling opening hacker news and seeing your project at the top :)

In iTerm2's case it's because of bad decisions about a decade ago. The data model is read & written on the main thread. The main thread is solely responsible for drawing operations if you use the standard drawRect: interface on NSView. That means that a slow draw blocks it from processing more data. Other work, like reading from the socket and parsing bytes into tokens was offloaded onto other threads years ago. Unwinding all the assumptions about single-threadedness is nearly impossible. The only way to reduce the main thread's workload is to use a GPU renderer because building the data structures the GPU needs can be done off the main thread after a quick copy of the necessary state.

Re:iTerm2 has a new drawing engine that uses Metal 2 by hoistbypetard on Sunday July 29, 2018 @10:33AM (#17638323)
Thanks for iTerm2. I've been using iTerm since 2006-ish and iTerm2 since approximately whenever it came out (2011-ish?) :)

Apple's sorry hardware situation recently pushed me to move to Linux on a ThinkPad for most of my daily use, so I don't use iTerm2 as much now as I used to. (And, naturally, just after the return period on my ThinkPad expired, Apple rolled out a MBP with 32GB RAM X()

Your software made my life better every day for years. It was the first program I downloaded and installed after LittleSnitch when I set up a new Mac. Thank you.

Re:iTerm2 has a new drawing engine that uses Metal 2 by dpkonofa on Saturday July 28, 2018 @11:30PM (#17636366)
Just want to add my thanks for iTerm2. Having an IRL Quake-style console at work just makes me feel like a kid all day long even though I'm not messing around anymore but doing real work. :-P
Re:iTerm2 has a new drawing engine that uses Metal 2 by bgdkbtv on Monday July 30, 2018 @07:58PM (#17649364)
Somewhat unrelated to the topic, but why did you decide to host source code on GitHub, but project issues and feature suggestions on GitLab?
Re:iTerm2 has a new drawing engine that uses Metal 2 by chris_st on Saturday July 28, 2018 @09:02PM (#17635906)
Hey, happy user here -- thanks for doing iTerm2!
Re:iTerm2 has a new drawing engine that uses Metal 2 by rbanffy on Sunday July 29, 2018 @02:16AM (#17636787)
Thanks a lot for iTerm2.

BTW, I'd love to help to add overline support. Mind if I open an issue and ask for some pointers?

Re:iTerm2 has a new drawing engine that uses Metal 2 by gnachman on Sunday July 29, 2018 @03:15PM (#17639771)
File an issue! There are only a few bits left for style so they have to be used judiciously. Or come up with a better scheme for storing character attributes.
Re:iTerm2 has a new drawing engine that uses Metal 2 by __blockcipher__ on Sunday July 29, 2018 @10:38PM (#17641669)
Really dumb question here: how can I map cmd+ctrl+w to “close other tabs”? It’s the default in Terminal.app, but I just installed iTerm2 a day ago and havent found an option in the settings for it.
Re:iTerm2 has a new drawing engine that uses Metal 2 by rbanffy on Tuesday July 31, 2018 @01:56AM (#17650865)
Re:iTerm2 has a new drawing engine that uses Metal 2 by natvert on Saturday July 28, 2018 @10:52PM (#17636254)
Yes, thank you! Perhaps this has been asked before, but is there any hope of an Ubuntu port?
Re:iTerm2 has a new drawing engine that uses Metal 2 by gnachman on Saturday July 28, 2018 @11:04PM (#17636293)
Only if openstep catches up with Apple, or I retire. I wouldn’t hold my breath.
Re:iTerm2 has a new drawing engine that uses Metal 2 by natvert on Sunday July 29, 2018 @11:07AM (#17638498)
Haha, ok. Thank you again for all your hard work! Iterm2 is 90% the reason I pay a premium for a Mac. I would gladly skip paying the apple tax and put the funds toward iterm2 on other platforms if it ever becomes available :)
Re:iTerm2 has a new drawing engine that uses Metal 2 by fooker on Sunday July 29, 2018 @03:02AM (#17636916)
Try yakuake, if you haven't.
Re:iTerm2 has a new drawing engine that uses Metal 2 by samirez on Sunday July 29, 2018 @04:17AM (#17637080)
Appreciate the insights here - and also the pragmatic approach!
Re:iTerm2 has a new drawing engine that uses Metal 2 by xtreak29 on Saturday July 28, 2018 @10:46PM (#17636228)
Thanks much for iTerm 2 :)
Re:iTerm2 has a new drawing engine that uses Metal 2 by isczhu on Monday July 30, 2018 @06:10AM (#17643365)
Thanks for iTerm2!
Re:iTerm2 has a new drawing engine that uses Metal 2 by andrewstuart2 on Saturday July 28, 2018 @07:54PM (#17635685)
> Like in a video game, the world moves at the same rate regardless of the frame rate

If only this were true. There are plenty of games where the frame rate is capped at 60hz because the physics engine is coupled to it. If you force a framerate increase via .ini tweaks or something, you get really weird physics. I think Skyrim had this problem. Also, there are examples of where changing the network tick rate [1] can affect the physics engines.

[1] https://www.youtube.com/watch?v=sB5u96Vgyks

Re:iTerm2 has a new drawing engine that uses Metal 2 by jdmnd on Sunday July 29, 2018 @11:13AM (#17638526)
I found this[0] discussion on Jonathon Blow's youtube channel about game physics/framerate dependence. It certainly seems to more than simply a problem of software architecture as some commenters appear to suggesting here.

[0] https://www.youtube.com/watch?v=fdAOPHgW7qM

Re:iTerm2 has a new drawing engine that uses Metal 2 by saagarjha on Saturday July 28, 2018 @09:39PM (#17636016)
What happens if your computer can't support a 60 Hz frame rate?
Re:iTerm2 has a new drawing engine that uses Metal 2 by LeoNatan25 on Saturday July 28, 2018 @10:01PM (#17636095)
The games slow down. Until recently, most Japanese games were tightly tied to 30hz or 60hz logic, and would speed up or slow down if forced (willfully or not) to run at different frequency. This is not strictly a Japanese games phenomenon, but I've seen it mostly in PC ports of Japanese developed games for consoles.

To me, that's bad software design. 40 years ago, developers used to sync their logic to the refresh cycles of the target machine's display. That's amazing, but also something that should not happen in 2018 (or 2010 or 1998).

Re:iTerm2 has a new drawing engine that uses Metal 2 by peterburkimsher on Sunday July 29, 2018 @12:29AM (#17636523)
Isn't that the reason for the Turbo button?

For the younglings: it was a physical button to underclock the CPU on old PCs.

https://en.m.wikipedia.org/wiki/Turbo_button

Re:iTerm2 has a new drawing engine that uses Metal 2 by LeoNatan25 on Sunday July 29, 2018 @04:52AM (#17637161)
Yes, but the turbo button is and should remain a relic of the past, rather than a cornerstone of modern gaming design.
Re:iTerm2 has a new drawing engine that uses Metal 2 by yoklov on Sunday July 29, 2018 @12:37AM (#17636535)
Eh, it’s extremely difficult to write a physics engine that behaves predictably with variable timesteps. Likely impossible at the extremes.
Re:iTerm2 has a new drawing engine that uses Metal 2 by GolDDranks on Sunday July 29, 2018 @02:51AM (#17636879)
The framerate of the physics simulation can be decoupled from the frame rate of the rendering loop. For example, you can aim for a 30fps steady timestep simulation and a vsync-capped rendering. you can then use interpolation methods for quick-and-dirty calculation to smooth the movement to match the rendering timestep.
Re:iTerm2 has a new drawing engine that uses Metal 2 by fnordsensei on Sunday July 29, 2018 @02:09AM (#17636772)
My ignorance on this subject is a vast abyss, but reality seems to work OK with this, because "subjective" and "objective" time can be decoupled. The world doesn't really care if your video camera takes a snapshot every 1/30th or 1/60th of a second, it'll keep doing whatever it is doing at its own pace.

Can't a virtual world be built with the same principles?

Re:iTerm2 has a new drawing engine that uses Metal 2 by cuban-frisbee on Sunday July 29, 2018 @03:21AM (#17636959)
They can and they are. Take for example Forza Motorsport, the physics engine, i.e. How the cars react to different road conditions updates at 360 hz while the graphics updates at 60 hz.
Re:iTerm2 has a new drawing engine that uses Metal 2 by vbezhenar on Sunday July 29, 2018 @04:33AM (#17637115)
May be real world is simulated with 5.39e44 fps, so you won't feel the difference between 30 fps or 60 fps camera. You can't simulate virtual world with similar performance yet.
Re:iTerm2 has a new drawing engine that uses Metal 2 by IshKebab on Sunday July 29, 2018 @06:29AM (#17637377)
No it isn't. You might need to set a minimum time step to avoid instability but a variable time step is trivial.

The only place it might cause issues is if you need it to be deterministic, e.g. for multiplayer.

Re:iTerm2 has a new drawing engine that uses Metal 2 by angry_octet on Sunday July 29, 2018 @07:56PM (#17641110)
I read that comment and initially had the same response as you. But on re-reading it is good advice, and one shouldn't focus on edge cases in language, when IRL we would probably all be in furious agreement.

Obviously for most models it is simple to adapt to variable simulation periods without instability, either by microstepping (which commonly occurs anyway because the natural simulation freq is much faster than 60Hz), or because the process is just solving a stable DE or doing basic physics over a different period.

For debugging it is often much easier to run physics at a fixed rate. You do get different results at different rates due to numerical precision issues and error accumulation.

Re:iTerm2 has a new drawing engine that uses Metal 2 by tomc1985 on Saturday July 28, 2018 @07:17PM (#17635557)
Unless the programmer specifically decouples graphics from the rest of the program, anything that renders to the screen will have to wait for that command to finish drawing. It will effectively govern the throughput of any program that both prints lots of text to screen and is not appropriately multithreaded.
Re:iTerm2 has a new drawing engine that uses Metal 2 by crawshaw on Saturday July 28, 2018 @07:37PM (#17635636)
Evan knows that. His question is why isn't it normal for the graphics to be explicitly decoupled in terminal emulators that care about draw performance.
Re:iTerm2 has a new drawing engine that uses Metal 2 by altfredd on Saturday July 28, 2018 @10:45PM (#17636222)
Wrong. Splitting logic into separate threads is not necessary. In order to make the engine independent from FPS, you have to decide, how to handle excess/missing output. You can buffer, transform, average or simply drop excess frames. Missing frames can be worked around by repeating previous frames or reducing effective resolution (often done with a bit of blur — hi, Nvidia!). In either case there are limits to what can be achieved with those workarounds — eventually you'd have to throttle the fastest producer (renderer, physics engine or player input). All of that can be done just fine without threads — using asynchronous programming (incidentally, this is why many advanced rendering APIs are asynchronous).

Most games can simply "drop frames", when renderer isn't up to speed with engine. The result is minor loss of visual fidelity, which usually isn't too bad, unless FPS are horribly low. Things are more tricky for terminals, because 1) they need to maintain scrollback history 2) their output is more blocky, so "dropping frames" leads to horribly-looking ASCII animations.

There are some terminals, that do start dropping output, when rendered can't keep up. Others (for example, xterm) do refuse to do that by default, because they assume, that underlying program may do better job at handling low framerate, than general-purpose terminal emulator.

Either way, if you want to achieve fluid, visually pleasing rendering, you renderer should be as fast as possible.

Re:iTerm2 has a new drawing engine that uses Metal 2 by jayd16 on Saturday July 28, 2018 @10:55PM (#17636264)
>Splitting logic into separate threads is not necessary.

Unless you're already using Vulkan/Metal your render thread will most certainly be lockstep with the GPU and that will block your CPU throughput.

You haven't described CPU/GPU independence at all. You're just talking about sacrificing the FPS for CPU perf.

Re:iTerm2 has a new drawing engine that uses Metal 2 by evmar on Monday August 06, 2018 @03:20AM (#17695735)
I don't know why this one was downvoted. It is exactly right. You don't need threads, you just need your function that parses input to not try to write everything it sees to the screen (drop frames).
Re:iTerm2 has a new drawing engine that uses Metal 2 by sedatk on Saturday July 28, 2018 @07:22PM (#17635577)
The IRC client XiRCON did that back in 90’s. Regardless how slow your machine is you always got the output instantly, albeit with less FPS.
Re:iTerm2 has a new drawing engine that uses Metal 2 by h2j24 on Saturday July 28, 2018 @09:18PM (#17635942)
Is that truly the case for games? I thought game logic was usually programmed against a clock, so that the game logic isn't dependent on running at some pre-determined frequency. However, is it typically the case that the number of ticks per second is independent of the render time?
Re:iTerm2 has a new drawing engine that uses Metal 2 by AgentME on Saturday July 28, 2018 @10:31PM (#17636185)
Some games do it differently, but evmar's advice matches recommendations that I've seen for game engines[0].

[0] https://gafferongames.com/post/fix_your_timestep/

Re:iTerm2 has a new drawing engine that uses Metal 2 by jayd16 on Saturday July 28, 2018 @08:50PM (#17635871)
Hmm well my guess is that for a lot of terminal apps they're expecting to draw directly to the screen without ever dropping a frame.

You could add a buffer but if you can't drop frames that will only smooth out vsync wait.

Re:iTerm2 has a new drawing engine that uses Metal 2 by ebbv on Saturday July 28, 2018 @08:15PM (#17635768)
Nobody bothers to decouple them because usually rendering a terminal is trivial and the output rate isn’t as fast for most use cases. But it sounds like if you’ve done it before it might be a cool thing to contribute to your preferred open source terminal program (if you want to.)
Re:iTerm2 has a new drawing engine that uses Metal 2 by ComputerGuru on Sunday July 29, 2018 @02:33AM (#17636833)
That’s simply not true. A lot of terminals can’t output even ‘ls’ fast enough once colored output is enabled.
Re:iTerm2 has a new drawing engine that uses Metal 2 by hk__2 on Sunday July 29, 2018 @05:27AM (#17637243)
> But it sounds like if you’ve done it before it might be a cool thing to contribute to your preferred open source terminal program (if you want to.)

It’s not trivial to implement it in an existing codebase. Quoting from ITerm2’s Subpixel Antialiasing document:

> iTerm2’s design burdens the main thread with handling input from the TTY. A better design would perform only drawing and other UI activity on the main thread, but it’s too hard to change as there are thousands of implicit assumptions baked in to the code.