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

Speed up gopls startup #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ftassi
Copy link

@ftassi ftassi commented May 19, 2022

gopls image startup is really slow. This is mainly due to the usermod and chmod performed by the entrypoint script.
I tried to implement another dockerfile which uses the official golang images. They are installing go in a world writable directory, so there is no need for a dedicated user any more (hence no usermod and the image spins in milliseconds).

I had to define a GOCACHE dir, but apart from that the image it quite simple and seems to be working fine.

I am testing it on my env with this conf

    capabilities = capabilities,
    cmd = require'lspcontainers'.command('ftassigopls', {
            image = 'lspcontainers/gopls',
            network="bridge",
            cmd_builder = function (runtime, workdir, image, network)
                local volume = workdir..":"..workdir..":z"
                local env = vim.api.nvim_eval('environ()')
                local gopath = env.GOPATH or env.HOME.."/go"
                local gopath_volume = gopath..":"..gopath..":z"

                local group_handle = io.popen("id -g")
                local user_handle = io.popen("id -u")

                local group_id = string.gsub(group_handle:read("*a"), "%s+", "")
                local user_id = string.gsub(user_handle:read("*a"), "%s+", "")

                group_handle:close()
                user_handle:close()

                local user = user_id..":"..group_id

                return {
                    runtime,
                    "container",
                    "run",
                    "--interactive",
                    "--network="..network,
                    "--rm",
                    "--workdir="..workdir,
                    "--volume="..volume,
                    "--user="..user,
                    image
                }
            end,
        }),
    -- cmd = require'lspcontainers'.command('gopls'),
}

Go runtime is installed in /go which is word writable so there is no
need for a dedicated user. This removes the need to usermod at runtime
which was very time consuming. Not having to manipulate the user at
runtime allows to remove the entrypoint script entirely.

With this setup the language server is up and running in milliseconds
rather than seconds.

I based this image on official golang alpine image to avoid as much
duplication as possible
@ftassi
Copy link
Author

ftassi commented May 19, 2022

This could also solve lspcontainers/lspcontainers.nvim#68 (not sure though)

@jgero
Copy link
Contributor

jgero commented May 23, 2022

I will test it later today or in the next few days, thanks!

@jgero
Copy link
Contributor

jgero commented May 25, 2022

Okay I can confirm, this solves the --user related problems of lspcontainers/lspcontainers.nvim#68.

@jgero
Copy link
Contributor

jgero commented Jun 15, 2022

I just ran into a problem with this and I am not sure whether this is again podman related or not. While using your image with the --userid flag I get a permission denied error when trying to download a go package (via code action) into the volume. When I remove the --userid flag it works fine again. Is this the case for you? Do you have any ideas what causes this?

@erikreinert erikreinert added the enhancement New feature or request label Jun 17, 2022
@erikreinert erikreinert self-assigned this Jun 17, 2022
@erikreinert
Copy link
Contributor

I believe I may have improved this in a separate PR if you don't mind testing this LSP and seeing if it's running faster. Thank you!

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

Successfully merging this pull request may close these issues.

3 participants