Package convex.core.lang
Class Juice
java.lang.Object
convex.core.lang.Juice
Static class defining juice costs for executable operations.
"LISP programmers know the value of everything and the cost of nothing." -
Alan Perlis
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longJuice cost for accepting an offer of Convex coins.protected static final longstatic final longJuice for an apply operation Bit of cost to allow for parameter construction.protected static final longstatic final longJuice cost for an 'assoc'protected static final longJuice for balance core function.protected static final longJuice for creation of a blob.protected static final longJuice required to build a data structure.protected static final longprotected static final longJuice required per element changed when building a data structure.static final longJuice required to call an Actor Slightly expensive for context switching?static final longJuice for a very cheap operation.static final longJuice cost to compile a Constant valuestatic final longJuice cost to compile a Constant valuestatic final longJuice cost to compile a general AST nodestatic final longJuice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).static final longJuice required to resolve a constant value Very cheap, no allocs / lookup.static final longJuice required to look up a core symbol.static final longJuice to create an account.static final longJuice required to define a value in the current environment.static final longJuice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deployingstatic final longJuice required to execute a Do block Very cheap, no allocs.static final longJuice for general object equality comparison Pretty cheap.protected static final longProbably should be expensive?static final longJuice cost to expand a constantstatic final longJuice cost to expand a sequenceprotected static final longJuice for data structure get.static final longJuice for a cryptographic hash Expensive.protected static final longstatic final longJuice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?static final longJuice required to execute a Let block Fairly cheap but some parameter munging required.static final longstatic final longJuice required to look up a value in the local environment.static final longJuice required to look up a value in the dynamic environment.static final longJuice required to look up a symbol with a regular Addressprotected static final longstatic final longJuice cost for extracting metadata from a Syntax object.static final longJuice for numeric comparison Pretty cheap.static final longMake this quite expensive.static final longstatic final longJuice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.protected static final longstatic final longJuice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.static final longJuice cost to schedulestatic final longDefault future schedule juice (10 per hour) This makes scheduling a few hours / days ahead cheap but year is quite expensive (~87,600).static final longstatic final longVariable Juice cost for set comparisonstatic final longJuice for a simple built-in core function.static final longstatic final longprotected static final longJuice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.protected static final longstatic final longJuice cost for constructing a Syntax Object.static final longJuice for a transfer execution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final longadd(long a, long b) Saturating addition.static final longaddMul(long a, long b, long c) Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.static longbuildBlobCost(long n) Gets the Juice cost for building a Blobstatic longbuildCost(ACountable<ACell> counted, long n) Computes the data build cost of a countable structure of given lengthstatic longbuildDataCost(long n) Gets the Juice cost for building a data structurestatic longbuildStringCost(long n) Gets the Juice cost for building a Stringstatic longlimitString(Context<?> context) Gets the maximum number of string bytes that can be constructedstatic final longmul(long a, long b) Saturating multiply.
-
Field Details
-
CONSTANT
public static final long CONSTANTJuice required to resolve a constant value Very cheap, no allocs / lookup.- See Also:
-
DEF
public static final long DEFJuice required to define a value in the current environment. We make this somewhat expensive - we want to discourage over-use as a general rule since it writes to global chain state. However memory accounting helps discourage superfluous defs, so it only needs to reflect execution cost.- See Also:
-
LOOKUP
public static final long LOOKUPJuice required to look up a value in the local environment.- See Also:
-
CORE
public static final long COREJuice required to look up a core symbol.- See Also:
-
LOOKUP_DYNAMIC
public static final long LOOKUP_DYNAMICJuice required to look up a value in the dynamic environment. Potentially a bit pricey since read only, but might hit storage so.....- See Also:
-
LOOKUP_SYM
public static final long LOOKUP_SYMJuice required to look up a symbol with a regular Address- See Also:
-
DO
public static final long DOJuice required to execute a Do block Very cheap, no allocs.- See Also:
-
LET
public static final long LETJuice required to execute a Let block Fairly cheap but some parameter munging required. TODO: revisit binding costs?- See Also:
-
COND_OP
public static final long COND_OPJuice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).- See Also:
-
LAMBDA
public static final long LAMBDAJuice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?- See Also:
-
CALL_OP
public static final long CALL_OPJuice required to call an Actor Slightly expensive for context switching?- See Also:
-
BUILD_DATA
protected static final long BUILD_DATAJuice required to build a data structure. Make a bit expensive?- See Also:
-
BUILD_PER_ELEMENT
protected static final long BUILD_PER_ELEMENTJuice required per element changed when building a data structure. Map entries count as two elements. We need to be a bit harsh on this! Risk of consuming too much heap space, might also result in multiple allocs for tree structures.- See Also:
-
MAP
protected static final long MAP- See Also:
-
REDUCE
protected static final long REDUCE- See Also:
-
EQUALS
public static final long EQUALSJuice for general object equality comparison Pretty cheap.- See Also:
-
NUMERIC_COMPARE
public static final long NUMERIC_COMPAREJuice for numeric comparison Pretty cheap. Bit of casting perhaps.- See Also:
-
APPLY
public static final long APPLYJuice for an apply operation Bit of cost to allow for parameter construction. Might need to revisit for bigger sequences?- See Also:
-
HASH
public static final long HASHJuice for a cryptographic hash Expensive.- See Also:
-
CHEAP_OP
public static final long CHEAP_OPJuice for a very cheap operation. O(1), no new cell allocations or non-trivial lookups.- See Also:
-
SIMPLE_FN
public static final long SIMPLE_FNJuice for a simple built-in core function. Simple operations are assumed to require no expensive resource access, and operate with O(1) allocations- See Also:
-
STR
protected static final long STRJuice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.- See Also:
-
ARITHMETIC
protected static final long ARITHMETIC- See Also:
-
ADDRESS
protected static final long ADDRESS- See Also:
-
BALANCE
protected static final long BALANCEJuice for balance core function. Some lookups required- See Also:
-
BLOB
protected static final long BLOBJuice for creation of a blob. Fairly cheap but needs per-byte cost- See Also:
-
BUILD_PER_BYTE
protected static final long BUILD_PER_BYTE- See Also:
-
GET
protected static final long GETJuice for data structure get. Hash lookup possibly required.- See Also:
-
KEYWORD
protected static final long KEYWORD- See Also:
-
SYMBOL
protected static final long SYMBOL- See Also:
-
TRANSFER
public static final long TRANSFERJuice for a transfer execution. Some account updates- See Also:
-
SIMPLE_MACRO
public static final long SIMPLE_MACRO- See Also:
-
RECUR
public static final long RECURJuice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.- See Also:
-
DEPLOY_CONTRACT
public static final long DEPLOY_CONTRACTJuice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deploying- See Also:
-
EVAL
protected static final long EVALProbably should be expensive?- See Also:
-
COMPILE_CONSTANT
public static final long COMPILE_CONSTANTJuice cost to compile a Constant value- See Also:
-
COMPILE_LOOKUP
public static final long COMPILE_LOOKUPJuice cost to compile a Constant value- See Also:
-
COMPILE_NODE
public static final long COMPILE_NODEJuice cost to compile a general AST node- See Also:
-
EXPAND_CONSTANT
public static final long EXPAND_CONSTANTJuice cost to expand a constant- See Also:
-
EXPAND_SEQUENCE
public static final long EXPAND_SEQUENCEJuice cost to expand a sequence- See Also:
-
SCHEDULE
public static final long SCHEDULEJuice cost to schedule- See Also:
-
SCHEDULE_MILLIS_PER_JUICE_UNIT
public static final long SCHEDULE_MILLIS_PER_JUICE_UNITDefault future schedule juice (10 per hour) This makes scheduling a few hours / days ahead cheap but year is quite expensive (~87,600). Also places an upper bound on advance schedules. TODO: review this. Maybe not needed given memory accounting?- See Also:
-
RETURN
public static final long RETURNJuice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.- See Also:
-
ACCEPT
public static final long ACCEPTJuice cost for accepting an offer of Convex coins. Define this to be equal to a transfer.- See Also:
-
SYNTAX
public static final long SYNTAXJuice cost for constructing a Syntax Object. Fairly lightweight.- See Also:
-
META
public static final long METAJuice cost for extracting metadata from a Syntax object.- See Also:
-
ASSOC
public static final long ASSOCJuice cost for an 'assoc'- See Also:
-
SET_COMPARE_PER_ELEMENT
public static final long SET_COMPARE_PER_ELEMENTVariable Juice cost for set comparison- See Also:
-
CREATE_ACCOUNT
public static final long CREATE_ACCOUNTJuice to create an account. Some cost for new account data structure entry.- See Also:
-
QUERY
public static final long QUERY- See Also:
-
LOG
public static final long LOG- See Also:
-
SPECIAL
public static final long SPECIAL- See Also:
-
SET_BANG
public static final long SET_BANG- See Also:
-
PEER_UPDATE
public static final long PEER_UPDATEMake this quite expensive. Discourage spamming Peer updates- See Also:
-
-
Constructor Details
-
Juice
public Juice()
-
-
Method Details
-
addMul
public static final long addMul(long a, long b, long c) Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.- Parameters:
a- First number (to be added)b- Second number (to be multiplied)c- Thirst number (to be multiplied)- Returns:
- long result, capped at Long.MAX_VALUE
-
mul
public static final long mul(long a, long b) Saturating multiply. Returns Long.MAX_VALUE on overflow.- Parameters:
a- First numberb- Second number- Returns:
- long result, capped at Long.MAX_VALUE
-
add
public static final long add(long a, long b) Saturating addition. Returns Long.MAX_VALUE on overflow.- Parameters:
a- First numberb- Second number- Returns:
- long result, capped at Long.MAX_VALUE
-
buildCost
Computes the data build cost of a countable structure of given length- Parameters:
counted- Counted data structure, used for typen- Element count of data structure constructed- Returns:
-
buildStringCost
public static long buildStringCost(long n) Gets the Juice cost for building a String- Parameters:
n- Length of String- Returns:
- Juice cost
-
buildBlobCost
public static long buildBlobCost(long n) Gets the Juice cost for building a Blob- Parameters:
n- Length of Blob- Returns:
- Juice cost
-
limitString
Gets the maximum number of string bytes that can be constructed- Parameters:
context- Context to check for Juice- Returns:
- Limit in number of bytes
-
buildDataCost
public static long buildDataCost(long n) Gets the Juice cost for building a data structure- Parameters:
n- Element count of data structure (number of CVM values)- Returns:
- Juice cost
-