Skip to content

existing cache values are never used #109

Description

@kpm

The cache struct in parser.go seems to be there so that existing values can be reused for performance, however when we look at the getValue method as below, getValue always grabs a new value past the existing length of the c.vs slice. The only other accesses to the cache are to reset it. So this means that values saved on the c.vs slice are never accessed (except for the last one that was just added for a short time). Am I missing something? Thanks.

func (c *cache) getValue() *Value {
	if cap(c.vs) > len(c.vs) {
		c.vs = c.vs[:len(c.vs)+1]
	} else {
		c.vs = append(c.vs, Value{})
	}
	// Do not reset the value, since the caller must properly init it.
	return &c.vs[len(c.vs)-1]
}

Because c.getValue is called every time we parse a json entity, the whole parse tree has another copy in the cache, and this causes excessive memory usage for no apparent benefit. I was able to parse a large file with nested arrays after changing getValue to the below. It was a 1.4GB file, and was killed on my 32GB RAM machine after reaching 26GB resident RAM. When I tried changing getValue to the below, the file was able to be parsed and used about 9.7GB of resident ram.

func (c *cache) getValue() *Value {
	var v Value
	return &v
}

The large file can be downloaded from https://data.acgov.org/datasets/2b026350b5dd40b18ed7a321fdcdba81_0/about , and selecting geojson format.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions