optimize: reduce memory consumption of Token class by 50% on 64Bit
By removing the ParseSession pointer from it, we get rid of 8 bytes and furthermore reduce the alignment size to 4. This way, we now only require 12 bytes per token compared to 24 bytes previously. This also allows us to define the Token class as a primitive type, potentially speeding up the TokenStream even further. The "cost" is a changed API, to get the string representation of a token, one must now ask the TokenStream. In practice this is very rarely a real pita, as before one often did stream->token(i)->symbol() now you just do stream->symbol(i) Furthermore I've consolidated the tons of custom "AST* node to QString" functions into one central ParseSession::stringForNode. Finally, I've replaced some costly token.symbol() == IndexedChar("somechar") with the much faster token.kind == Token_xyz comparisons. All in all, this should a) make our code faster and b) let it use much less memory while at it. For the big resource file in the bug below, the difference of 50% in the Token class results in ~250MB less memory consumption CCBUG: 291248
parent
0e9c1916
Please register or sign in to comment