Hi all --

I'm writing an interpreter for a simple scripting language, and the
main data structure will naturally be an AST. ASTs tend to be deeply
nested, consisting of many small nodes. The node structs look like

type ASTAssignment struct {
target string
expr ASTNode

type ASTFunctionCall struct {
function ASTExpression
args []ASTExpression

...so the cost of copying one single node is pretty small. But I'm
worried about the overhead when there are thousands of nodes kicking

The obvious overhead is the cost of copying bytes in memory. But
should I also be worried about allocation costs and the impact on GC?
My gut instinct says yes, but I'm unclear on the details. Has anyone
written a guide about when/why/how to worry about allocation and GC

On a related note, I'm also confused about the costs of a slice of
interface type vs a slice of concrete type. Consider my
ASTFunctionCall above, which includes

args []ASTExpression

ASTExpression is an interface type: lots of AST nodes are expressions.
Currently I'm putting plain structs into my node lists, without

// for arg list (op1+op2, "foo")
arg0 := ASTAdd{op1, op2}
arg1 := ASTString{"foo"}
args = []ASTExpression {arg0, arg1}

What exactly happens to that concrete ASTAdd struct when it's put into
the []ASTExpression slice-of-interfaces? Is the struct copied? Should
I use pointers instead to reduce copies?

Thanks --



Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
groupgolang-nuts @
postedNov 16, '12 at 5:08p
activeNov 25, '12 at 8:04p



site design / logo © 2022 Grokbase