[yul-phaser] ProgramCache::calculateTotalCachedCodeSize(): Replace default weights with ones that better correlate with memory usage

This commit is contained in:
Kamil Śliwak
2020-05-20 16:47:23 +02:00
parent bff012c76d
commit 1fa689e951
3 changed files with 31 additions and 6 deletions
+25
View File
@@ -19,6 +19,8 @@
#include <tools/yulPhaser/Program.h>
#include <libyul/optimiser/Metrics.h>
#include <map>
#include <string>
@@ -44,6 +46,29 @@ struct CacheEntry
*/
struct CacheStats
{
/// Weights used to compute totalCodeSize.
/// The goal here is to get a result proportional to the amount of memory taken by the AST.
/// Each statement/expression gets 1 just for existing. We add more if it contains any extra
/// data that won't be visited separately by ASTWalker.
static yul::CodeWeights constexpr StorageWeights = {
/* expressionStatementCost = */ 1,
/* assignmentCost = */ 1,
/* variableDeclarationCost = */ 1,
/* functionDefinitionCost = */ 1,
/* ifCost = */ 1,
/* switchCost = */ 1,
/* caseCost = */ 1,
/* forLoopCost = */ 1,
/* breakCost = */ 1,
/* continueCost = */ 1,
/* leaveCost = */ 1,
/* blockCost = */ 1,
/* functionCallCost = */ 1,
/* identifierCost = */ 1,
/* literalCost = */ 1,
};
size_t hits;
size_t misses;
size_t totalCodeSize;