3 ms·
> Seems like a poor decision to use whitespace as a factor in estimating code size. It's a heuristic. It's always going to be more poor in some respect that do
by chrisseaton 8y ago
> Seems like a poor decision to use whitespace as a factor in estimating code size.
It's a heuristic. It's always going to be more poor in some respect that doing something precise. You could probably make it better in a million different ways, but it's suppose to be quick and simple.
- trhway 8y agoto inline the parsing must be done. Once parsing is done there is no newlines and semicolons, only AST nodes. Counting AST nodes is very quick and simple and provides for much better heuristic.
- chrisseaton 8y ago> to inline the parsing must be done Yes... that's the point. For your metric counting AST nodes you need to have parsed the method. The other heuristic works on unparsed source-code. So you don't waste time parsing a method that you won't inline. > Counting AST nodes is very quick and simple But parsing is neither. And you need to have done that first. I think (there's a paper I'm sure but can't find it) that parse time for JS applications is very substantial.
- MikeHolman 8y agoYou don't want to inline functions that haven't been parsed. If it hasn't been called by the time you are JITing, then it probably isn't going to be on a hot path.
- chrisseaton 8y agoIf it's been JITed then the AST may well have been discarded after the JIT completed! Doesn't V8 work like that today? You'll need to pass it again even if you have already parsed it! It's not hard to think of worst-cases. Think about an enormous function that you would not want to inline. It's been JITed, or it's running in a byte code interpreter, and the AST has been discarded. In your scheme you'll have to parse it to find it's too big. Huge waste of time, if you can see it's too large from the source code.
- MikeHolman 8y agoYou can't throw away your interpreter bytecode, because the JIT code needs to be able to bailout if a guard fails (e.g. if you specialized a var as an int and you get a non-int). So you can always use the size of your bytecode as an inlining heuristic (which is what Chakra does). Of course that wouldn't work before v8 had an interpreter, but they could have used other heuristics. For example, they could have used the size of the AST as a heuristic and saved that even after the AST gets thrown away.
- noselasd 8y ago> the parsing must be done. Therein lies the bulk of the problem, gcc doesn't parse the assembly code. The assembly is just copied with some minor string replacements for the registry names, and it's up to the assembler to deal with it and parse it.
- improbable22 8y agoEven with a simple heuristic, wouldn't you try to pick this magic number 600 so that it's about as likely to be too big as too small? Or is the problem very asymmetric, that inlining too-large pieces has dramatic downsides that failing to inline small pieces does not? Or is it just that the magic number was chosen decades ago, and the tradeoffs (perhaps re memory) are different now?
- chrisseaton 8y ago> wouldn't you try to pick this magic number 600... I guess ideally you'd run a sophisticated machine learning algorithm across a huge corpus of real-world code, on real-world devices to discover the right number... but in reality people just don't have time for that so they pick a number and move on. Can't really blame them.
- improbable22 8y agoI had a binary search in mind, if that counts as sophisticated :) Just surprised by orig GGP's assertion that more inlining would automatically be faster.
- IshKebab 8y agoRead the article - LLVM does it correctly.
- deleted 8y ago[deleted]