Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by matsemann on Tuesday June 29, 2021 @05:52AM
(#27673815)
In Java you could make an instance of a class doing
and if that string is created runtime, it's impossible to rule out usage of any dependency. So you basically have to tell the tools what to remove and what not to.
[ Parent
| on HN ]
Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by geokon on Tuesday June 29, 2021 @07:38AM
(#27674440)
Oh that's cool. I'm not intimately familiar with Java, so it's interesting to see how it's done. I figured it was something like that. Coming from C++, reflection seems like a giant useless codesmell - and there are all these issues further down the line because of it. And I get the impression most Java code doesn't even rely on it
Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by matsemann on Wednesday June 30, 2021 @03:31AM
(#27685938)
Most Java code actually does rely on it, but behind the scenes. So you could go years between writing any reflection code yourself, but libraries and frameworks use it to dynamically search for known stuff in the classpath and change behavior if it finds other class X, or use it to serialize to and from various formats and java objects, do stuff based on annotations etc.
Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by specialist on Tuesday June 29, 2021 @09:23AM
(#27675430)
Ages ago, I dimly recall debug tracing the classloader to see what is actually used. Something about troubleshooting Spring or some such.
Same strategy could be used for "tree shaking"?
I'll ponder how unused functions might be identified (during runtime).
Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by ygra on Tuesday June 29, 2021 @09:34AM
(#27675546)
Well, there are techniques. One of the hackier ones is probably the one described here: https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for...
Re:Tiny Treeshaker: JavaScript tree shaking in 200 lines of ...
by diamondo25 on Tuesday June 29, 2021 @09:07AM
(#27675251)
In theory the same applies for JavaScript, just eval an obfuscated piece of code and the shaker is none the wiser.