Giter Site home page Giter Site logo

Comments (9)

stamblerre avatar stamblerre commented on July 30, 2024

I would expect gocode to be a little slower in modules, but I haven't heard any reports as drastic as this. Is it usable or is it so slow that you don't get completions? Is your project extremely large? To check that it's not related to Atom, do you mind testing it out on the command line? You can run gocode on the command line with gocode -in /path/to/file.go autocomplete /path/to/file.go <offset>.

from gocode.

tekkamanendless avatar tekkamanendless commented on July 30, 2024

The problem seems to appear in parallel contexts. I captured calls that Atom was making and ran them through gocode on the command line. Serially, there is no problem and everything works somewhat slowly, but as expected. In parallel (I ran 30 at a time for this test), gocode's memory usage ballooned to over 3GB. After completing all of the requests, it maintains that memory footprint.

My guess is that in the Atom use case, it's calling gocode more or less for every character that I type, and because the run time is longer due to the known caching deficiency in this fork, it runs into the memory-ballooning problem.

In some of my other Go projects, I know that I've had to manually call the garbage-collector after an individual task was completed because Go just wouldn't free up that memory for whatever reason. Maybe that's the case here.

Anyway, I can provide my exact code and the script to reproduce my memory issue. My project is just five files for a grand total of 45KB. I'll see if I can make a smaller reproducer for you.

from gocode.

tekkamanendless avatar tekkamanendless commented on July 30, 2024

Simple reproducer:

/tmp/reproducer/go.mod

module example.com/memory-issue

require github.com/davecgh/go-spew v1.1.1

/tmp/reproducer/main.go

package main

import (
        "fmt"

        "github.com/davecgh/go-spew/spew"
)

func main() {
        fmt.Printf("Hello, world!")
        spew.Dump("Some text")
}

type s1 struct {
        a string
}

Run this, and it uses up 0.5GB:

for (( i=0; i<10; i++ )); do $GOPATH/bin/gocode -in /tmp/reproducer/main.go autocomplete /tmp/reproducer/main.go 154 & done; wait;

Run this, and it doubles it to 1.0GB:

for (( i=0; i<20; i++ )); do $GOPATH/bin/gocode -in /tmp/reproducer/main.go autocomplete /tmp/reproducer/main.go 154 & done; wait;

Memory consumption seems proportional to the number of concurrent requests.

from gocode.

stamblerre avatar stamblerre commented on July 30, 2024

Thank you for the repro. This seems to be the issue mentioned in #22. I was hesitant to merge this change because of the additional dependency, but I will begin reviewing it.

from gocode.

marcelino-m avatar marcelino-m commented on July 30, 2024

Same here, gocode is too slow in modules.

from gocode.

stamblerre avatar stamblerre commented on July 30, 2024

Just merged #22, so should be fixed.

from gocode.

tekkamanendless avatar tekkamanendless commented on July 30, 2024

Next up, I think that I'll need to patch go-plus for Atom to cancel requests faster (I don't think that it actually cancels requests after it sends the next ones).

from gocode.

tekkamanendless avatar tekkamanendless commented on July 30, 2024

Okay, short update: go-plus for Atom cancels its requests fairly quickly. I've patched gocode to call runtime.GC() after every request is handled, and while that helps, my gocode still balloons out to gigabytes and gigabytes (albeit much slower than before).

Is something still holding on to references to some of that stuff somewhere? I'll poke around with profiling it later.

from gocode.

tekkamanendless avatar tekkamanendless commented on July 30, 2024

Second update: calling debug.FreeOSMemory() instead of runtime.GC() after each request keeps gocode's memory from staying huge. It grows quickly while there are a bunch of requests in-flight, but it quickly drops back down to negligible amounts of memory immediately afterward.

from gocode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.