Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad performance in deep nested dynamic nodes #839

Closed
Entoryvekum opened this issue Mar 23, 2023 · 3 comments · Fixed by #852
Closed

Bad performance in deep nested dynamic nodes #839

Entoryvekum opened this issue Mar 23, 2023 · 3 comments · Fixed by #852

Comments

@Entoryvekum
Copy link

The code below implemented a snippet to help input matrix. It insert 2 spaces when & is detected and insert a new row when \\ is detected.

local function Matrix1()
    --SimpleMatrix
    local generateElm
    generateElm=function()
        return sn(
            nil,{
                t{"  "},
                i(1),
                d(2,
                    function (arg,snip,oldState)
                        local str=arg[1][1]
                        local len=string.len(str)
                        if string.sub(str,len,len)=="&" then
                            return sn(nil,{d(1,generateElm,{})})
                        elseif string.sub(str,len-1,len)=="\\\\" then
                            return sn(nil,{t{"",""},d(1,generateElm,{})})
                        else
                            return sn(nil,{})
                        end
                    end,
                    {1}
                )
            }
        )
    end
    snip(
        s({trig="mat",hidden=true},{
            t{"\\begin{matrix}",""},
            d(1,
                function (arg,snip,oldState)
                    return sn(nil,{d(1,generateElm,{})})
                end
            ),
            t{"","\\end{matrix}"}
        },{condition=mathZone})
    )
end
Matrix1()

The snip function will insert the snippet to the table that will be returned to the loader.

However, as the matrix getting larger the performance decreases dramaticly.

2023-03-23 20-47-08_3

The gif show tht after I typed in the entire row, vim sponse very slow.

@L3MON4D3
Copy link
Owner

Phuh, yeah I haven't given much thought to performance yet, there are probably many points that could be optimized.
But also, try not to nest the snippet as deep 😬😬
Maybe hook & in insertNode up to update the external_update_dynamicnode, and generate all those insertNodes as children of one dynamicNode

@L3MON4D3
Copy link
Owner

Did some testing, enter_node and set_mark_rgrav are the culprits:
b

Its purpose is to set the gravities of extmarks, such that text entered into the region of the node, actually shifts the extmarks into the correct direction.
Currently, this is handled by essentially touching all of the nodes in some snippetNode whenever one of its children is entered. We may be able to improve this by also adjusting gravities whenever a node is left, but I'll have to take a closer look to be certain

@L3MON4D3 L3MON4D3 linked a pull request Mar 29, 2023 that will close this issue
@L3MON4D3
Copy link
Owner

Did some work in #852, it's faster now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants