Hey guys, just wanted to know if there is any java...
# random
k
Hey guys, just wanted to know if there is any java/kotlin dead code elimination library? I am generating java & kotlin source files and wanted to remove unused imports or functions from the source files.
g
It doesn’t look as ded code elimination, it’s more like lint tool
Maybe just use something like klint
also, why do you add unused imports to generated files?
k
I have to do too many checks for imports during generation
So I am thinking of adding all imports at time of generation and remove those in post
g
To do that you need some tool like ktlint that detects unused imports
But it doesn’t sound for me as easier solution
do you use KotlinPoet for code generation?
k
No string builders
g
Use proper tool like KotlinPoet
it will handle imports for you
k
Its an old project and I can't migrate to kotlin poet
Long code base😅
g
Why then you worry about unused imports? %)
k
Doesn't it affects performance if we have unused imports
?
g
Not really
Because imports is source code abstraction which doesnt’ exist in bytecode
k
Anyways I was curious as there is DCE in Kotlin/JS so is there a similar java counterpart
g
and running code formatter for generated code is bigger performance problem than unused imports for compiler
it has nothing to do with DCE
k
I mean it will be a part of genration only
g
DCE or Proguard removes unused code
import is just import, it doesn’t exist after compilation
k
But the generated project will not have those redundant imports and functions
Should not*
g
Yes. better to avoid it just to have better code generation
k
Hmm
g
but add lint check and regenerate file tthat was just generated a few milliseconds ago doesn’t sound as perfromance optimization
For example dagger did this after code generation, just to reformat code and it disabled because of visible performance penalty, so they just generate properly formatted code now https://github.com/google/dagger/issues/368
Yes. better to avoid it just to have better code generation
I just mean, that if I use some code generation, I would like to have good generated code: formatted, with imports, no dead code etc But would I like to pay for this by longer code generation? Not really