Skip to content

Reduce allocations during resize with (setq frame-resize-pixelwise t) in your init! #66

Closed

Description

@jdtsmith

During resize, every 100ms (a rate which emacs itself may determine), a brand new pair of IOSurfaces are allocated (for the front and back frame buffer), at 5-50MB a pop. Pretty inefficient.

A better approach might be to limit the view of the IOSurface and resize it only to make it larger (at least during resize), with some increment like 25%, as needed. One complications is we also have old-school CGImage buffers and the new (optional) Metal buffers too, so they'd also need the same treatment. But could start with IOSurfaces. Once a given resize has completed (viewDidEndLiveResize) a "correct-size" frame buffer pair can be re-allocated.

Activity

  1. jdtsmith commented on Aug 3, 2025

    @jdtsmith
    OwnerAuthor

    Update: @gerd-moellmann suggested enabling frame-resize-pixelwise in the init. Not only does this make resizing very smooth, it entirely eliminates all the allocations of IOSurface VM.

    Instruments Allocations:

    Each of the following is a report from Instruments "Allocation" run sorted by Total Bytes. Each is about 11s worth of rapid resizing of the sole frame, showing my init.el (this is the emacs-30 branch).

    Without pixelwise

    1	All Heap & Anonymous VM	73.84 MiB	255978	15901933	3.04 GiB	16157911	Ratio: %0.02, %0.98
    0	All Heap Allocations	66.75 MiB	255973	15897266	687.54 MiB	16153239	Ratio: %0.02, %0.20
    0	All Anonymous VM	7.09 MiB	5	4667	2.37 GiB	4672	Ratio: %0.00, %0.78
    0	VM: IOSurface	7.00 MiB	2	214	2.29 GiB	216	Ratio: %0.00, %0.75
    

    With pixelwise

    1	All Heap & Anonymous VM	77.71 MiB	185970	429122	208.52 MiB	615092	Ratio: %0.37, %0.63
    0	All Heap Allocations	63.26 MiB	185965	426177	126.61 MiB	612142	Ratio: %0.30, %0.30
    0	All Anonymous VM	14.45 MiB	5	2945	81.91 MiB	2950	Ratio: %0.07, %0.32
    0	VM: IOSurface	14.41 MiB	2	0	14.41 MiB	2	Ratio: %0.07, %0.00
    

    Note in particular the last line in each: 2 persistent IOSurface allocations each (front/back frame buffer), but 214 temporary allocations totalling 2.3GB without pixelwise. I don't understand the reason for this difference, but I'll take it! Update: it doesn't redraw at all during resize until you release, but that's fine.

    Recommendation

    (setq frame-resize-pixelwise t)

    in your init.el!

  2. changed the title [-]Idea: reduce allocations during resize[/-] [+]Reduce allocations during resize with `(setq frame-resize-pixelwise t)` in your init![/+] on Aug 3, 2025
  3. jdtsmith commented on Aug 5, 2025

    @jdtsmith
    OwnerAuthor

    On the other hand, frame-resize-pixelwise prevents redisplay (somehow) during pixel-precise resize. Maybe this limitation could still be lifted with conservative only-growing frame buffer allocation. Worth looking at.

  4. Repository owner locked and limited conversation to collaborators on Sep 13, 2025
  5. converted this issue into a discussion #94 on Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions