Skip to content

[performance] A lot of CPU time consumed in tcell's CanDisplay() #3227

@dmaluka

Description

@dmaluka

CPU profiling via micro -profile shows that among the CPU time consumed by micro, a large fraction of time is usually spent inside tcell's CanDisplay() function (which is called from screen.SetContent() which is called from displayBuffer()).

In particular, most of the time inside CanDisplay() is spent in runtime.makeslice() -> runtime.mallocgc(), i.e. when allocating memory when creating slices. Most probably it is this code in CanDisplay():

	if enc := t.encoder; enc != nil {
		nb := make([]byte, 6)
		ob := make([]byte, 6)

Micro calls screen.SetContent() for virtually every character on the screen (including blank space), every time when updating the screen, so as a result, it spends time to repeatedly allocate memory for these 2 small temporary slices thousands of times every time.

Commit hash: 828871a
OS: Unix systems
Terminal: any

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