private long baseTransactionMemorySize(final Transaction tx, final Set<String> constantFields) {
    System.setProperty("jol.magicFieldOffset", "true");
    BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
    tx.writeTo(rlpOut);

    final var baseTx =
        Transaction.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)).detachedCopy();
    System.out.println(baseTx.getSender());
    System.out.println(baseTx.getHash());
    System.out.println(baseTx.getSize());

    final ClassLayout cl = ClassLayout.parseInstance(baseTx);
    System.out.println(cl.toPrintable());
    LongAdder baseTxSize = new LongAdder();
    baseTxSize.add(cl.instanceSize());
    System.out.println(baseTxSize);

    final SortedSet<FieldSize> fieldSizes = new TreeSet<>();

    GraphWalker gw = getGraphWalker(constantFields, fieldSizes);

    gw.walk(baseTx);

    fieldSizes.forEach(
        fieldSize -> {
          baseTxSize.add(fieldSize.size());
          System.out.println(
              "("
                  + baseTxSize
                  + ")["
                  + fieldSize.size()
                  + ", "
                  + fieldSize.path()
                  + ", "
                  + fieldSize
                  + "]");
        });
    System.out.println("Base tx size: " + baseTxSize);
    return baseTxSize.sum();
  }
Field which value is dynamic and can only be calculated at runtime
ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java