#compile without fmt.Println() for better performace

23 messages · Page 1 of 1 (latest)

hoary echo
#

Is it possible to compile without fmt.Prinltn() or log.Println() to make the code faster?

peak bone
#

is print() any faster?

boreal void
#

Have a const debug that you make false before compiling, then everything that says

if debug {
  fmt.Println("")
}```will get removed.
peak bone
#

does the stop the import?

boreal void
#

There's nothing to import if all its uses are eliminated

hoary echo
#

but that looks like a run time checking which requires it to be there in case the debug value changes to true ?

candid oxide
#

but debug is a const

#

so the theory is that since debug is a const, and it's false, it will never be true
therefore the compiler could simply omit that branch from the final output

#

with that said, it's theory, i have no idea on how i would prove it

#

i dont have enough knowledge to say if that's correct, but the one where const is false, seems to result in smaller output

peak bone
#

@tame ore

#

analysis

tame ore
candid oxide
#

sadly you cant use go variable injection to overwrite a const

#

only strings can be overwritten

tame ore
#

@candid oxide just use tags

candid oxide
#

yep was about to ask that

#

can you set build tags specific to a package
or do you just namespace the tag itself

#

since just using "debug" build tags might turn on debug for everyone's packages

hoary echo
#

Thank you @boreal void @candid oxide @tame ore

#

But the only thing that is bothering me is that if we have multiple packages in a project, we need to set the Debug const to false for each of them before compiling.

Can't set them all using ldflags since the ldflag can only add to a Var.