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 long
Juice cost for accepting an offer of Convex coins.protected static final long
static final long
Juice for an apply operation Bit of cost to allow for parameter construction.protected static final long
static final long
Juice cost for an 'assoc'protected static final long
Juice for balance core function.protected static final long
Juice for creation of a blob.protected static final long
Juice required to build a data structure.protected static final long
protected static final long
Juice required per element changed when building a data structure.static final long
Juice required to call an Actor Slightly expensive for context switching?static final long
Juice for a very cheap operation.static final long
Juice cost to compile a Constant valuestatic final long
Juice cost to compile a Constant valuestatic final long
Juice cost to compile a general AST nodestatic final long
Juice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).static final long
Juice required to resolve a constant value Very cheap, no allocs / lookup.static final long
Juice required to look up a core symbol.static final long
Juice to create an account.static final long
Juice required to define a value in the current environment.static final long
Juice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deployingstatic final long
Juice required to execute a Do block Very cheap, no allocs.static final long
Juice for general object equality comparison Pretty cheap.protected static final long
Probably should be expensive?static final long
Juice cost to expand a constantstatic final long
Juice cost to expand a sequenceprotected static final long
Juice for data structure get.static final long
Juice for a cryptographic hash Expensive.protected static final long
static final long
Juice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?static final long
Juice required to execute a Let block Fairly cheap but some parameter munging required.static final long
static final long
Juice required to look up a value in the local environment.static final long
Juice required to look up a value in the dynamic environment.static final long
Juice required to look up a symbol with a regular Addressprotected static final long
static final long
Juice cost for extracting metadata from a Syntax object.static final long
Juice for numeric comparison Pretty cheap.static final long
Make this quite expensive.static final long
static final long
Juice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.protected static final long
static final long
Juice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.static final long
Juice cost to schedulestatic final long
Default future schedule juice (10 per hour) This makes scheduling a few hours / days ahead cheap but year is quite expensive (~87,600).static final long
static final long
Variable Juice cost for set comparisonstatic final long
Juice for a simple built-in core function.static final long
static final long
protected static final long
Juice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.protected static final long
static final long
Juice cost for constructing a Syntax Object.static final long
Juice for a transfer execution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final long
add
(long a, long b) Saturating addition.static final long
addMul
(long a, long b, long c) Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.static long
buildBlobCost
(long n) Gets the Juice cost for building a Blobstatic long
buildCost
(ACountable<ACell> counted, long n) Computes the data build cost of a countable structure of given lengthstatic long
buildDataCost
(long n) Gets the Juice cost for building a data structurestatic long
buildStringCost
(long n) Gets the Juice cost for building a Stringstatic long
limitString
(Context<?> context) Gets the maximum number of string bytes that can be constructedstatic final long
mul
(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
-