From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yiming Chen Newsgroups: gmane.emacs.devel Subject: Re: [NS] Emacs 28 (IOSurface) renders much slower than Emacs 27 on macOS Big Sur Date: Tue, 01 Jun 2021 10:29:01 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8884"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: emacs-devel@gnu.org To: Alan Third Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 01 04:31:19 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnuBb-00029q-44 for ged-emacs-devel@m.gmane-mx.org; Tue, 01 Jun 2021 04:31:19 +0200 Original-Received: from localhost ([::1]:49386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnuBZ-0004pD-4L for ged-emacs-devel@m.gmane-mx.org; Mon, 31 May 2021 22:31:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnu9a-0003xJ-MU for emacs-devel@gnu.org; Mon, 31 May 2021 22:29:14 -0400 Original-Received: from mail-pl1-f182.google.com ([209.85.214.182]:43585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnu9Y-0007j0-Oa for emacs-devel@gnu.org; Mon, 31 May 2021 22:29:14 -0400 Original-Received: by mail-pl1-f182.google.com with SMTP id v12so6057974plo.10 for ; Mon, 31 May 2021 19:29:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version:content-transfer-encoding; bh=wmkGjYfO/aHvnxnPnY9YhIFDvqKbypAVNqK8+H4KNzo=; b=A/AKqx7EALbTztw78iC04Kay7irkQebKuhhUx8bmHh/2rsc0d5rI6kIT68fKjH8JuL 7LhfLW2a4+ycRZsb9hci1pjWUSRjtvluCH4z0jc1TJvRGE+Adk6q4lT0xAmhqO55JAVH 3HlJNoiGHHp2F8y9i7zjtHHY1laQSjF88YZlQ8dY82fC2RPi1xNLnibvKyl1ewKzMccv 8KFrIO7egCSKVkb9ZYzg+HlEq1FCecya8cDdDcdTzC291x3uzXQrSjaY3vBB5MrZqh1C Zo8Sl5Nn8q3t8dzkGOBXrgrL1dJ+zFXKIqkoo0MEMFyZcZ711IeKQVzuKAEJF03FO+08 ZVaQ== X-Gm-Message-State: AOAM5306uPM3agVqH3luVgJ4+/d+C4Ztd3QzxDSB+35SNWPyAocdONYh GE+YhPjkPs+u+PhkxJl4YQo6JwjFBEdEEA== X-Google-Smtp-Source: ABdhPJwMvZRDczo4fPOqm6PKFeLPr7lQ87nR8S3ryya1s1vWSDbjPy9Hs00wKuTdBzkh4E6MUwiwSA== X-Received: by 2002:a17:902:541:b029:f0:3187:409b with SMTP id 59-20020a1709020541b02900f03187409bmr23390092plf.47.1622514550249; Mon, 31 May 2021 19:29:10 -0700 (PDT) Original-Received: from Yiming-Chen-MacBook-Pro ([45.138.210.42]) by smtp.gmail.com with ESMTPSA id i8sm12134780pgt.58.2021.05.31.19.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 May 2021 19:29:09 -0700 (PDT) In-reply-to: Received-SPF: pass client-ip=209.85.214.182; envelope-from=dsdshcym@gmail.com; helo=mail-pl1-f182.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:270184 Archived-At: Hi Alan, Thanks for your reply and sorry for my late response. I've been using=20 https://github.com/emacs-mirror/emacs/commit/6f1e1ba633 for a few=20 days, and switched to=20 https://github.com/emacs-mirror/emacs/commit/784ec4b752 today. I feel the drawing performance improves a lot in=20 scratch/ns/surface-stuff branch, and I can finally see the improvements brought by native-compile. (since drawing is no longer a bottle-neck, maybe?) Thanks a lot for your work! Best, Yiming Alan Third writes: > On Sun, May 02, 2021 at 09:40:03PM +0800, Yiming Chen wrote: >> Hi there! >> I know that we've switched to a IOSurface based rendering for=20 >> nsterm in >> master branch. >> Now master renders more precisely than emacs-27 (i.e. less=20 >> flickers or >> blank screens.) >> But I feel that its rendering performance is much worse due to=20 >> the new >> buffering mechanism backed by IOSurface. > > Yup. That's the trade-off. > >> I think this poor rendering performance obscures the=20 >> improvements >> brought by native-compile. >> So I want to fix this performance issue and make Emacs runs on=20 >> macOS as >> fast as on Linux. > > I've spent over a year on-and-off on this. Good luck. > >> 1. Try to restore the nsterm behavior from Emacs27 (which is=20 >> much >> simpler than master IMHO), and start again from there >> >> I've reverted the code and made it compile (see >> ) >> But Emacs failed to start and raised an error `Font =E2=80=98Menlo=E2= =80=99=20 >> is not >> defined' > > That error must be something unrelated, as the drawing buffer=20 > changes > didn't touch the font code... I've got no suggestions on where=20 > to > start, though. My knowledge of font handling is non-existent. > > Actually, a quick look shows that you've enabled the nsfont=20 > backend > which just doesn't work in macOS, so I'd bet that's something to > investigate. > > I notice quite a few other problems... If I'm being honest,=20 > master has > diverged so much from emacs-27 that if I were to do this I'd=20 > probably > do it manually rather than try reverting commits. > > And I disagree that master is more complex than emacs-27. The=20 > endless > little work-arounds to try and get the emacs-27 rendering=20 > working made > it a much more brittle setup. > >> 2. Use layer-based view for rendering >> >> I found that macvim also faced the similar issue when macOS=20 >> 10.14 >> came out=20 >> (). >> They used NSImage to implement a double rendering solution >> (),=20 >> which was >> also slower than before. >> Then they switched from NSImage to layer-based view in >> . >> So I wonder if we can do the same. >> >> 3. Switch to CALayer (Core Animation) to use GPU (Metal)=20 >> rendering for >> even better performance than before >> >> If 2 (layer-based view) is possible, then I hope we can=20 >> leverage >> CALayer to make nsterm renders even faster. > > So... yes. The IOSurface system is already using layer-based=20 > drawing. > Have a look at updateLayer, for example. > > I'm not sure that CALayer really gives you anything in terms of > performance for this sort of thing. CoreAnimation is all about=20 > moving > different layers about efficiently, afaict, which isn't=20 > something we > need to do in Emacs. > > And bear in mind that in order to send an image to the Metal=20 > renderer > you still need to transfer it to the GPU, and Apple recommend=20 > using > IOSurface as it's the most efficient way to do that. > > AND Yamamoto Mitsuharu disabled Metal rendering in the Mac port=20 > as he > found the simple IOSurface based layer backing was faster. > > AND the Chromium developers decided to go with the simple=20 > IOSurface > based layer backing for performance reasons too. > > One place that a big improvement could be found is in disabling=20 > double > buffering and only drawing to one IOSurface, as you don't need=20 > to copy > the contents of the different IOSurfaces to each other. But I=20 > found > that produced unacceptable tearing effects. > > But all that said, it could be that copying viewWillDraw from=20 > master > to emacs-27 could solve some of the flickering. In my=20 > experimentation > I don't believe it does, but I've never been very good at=20 > inducing the > "flickering".