Skip to content

Commit e11ae2e

Browse files
committed
Reduce memory consumption of property names.
Property names were always required a string reference which consumed a large amount of memory for arrays. This patch reduces this consumption by directly storing the value part of certain strings. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent b2e1223 commit e11ae2e

18 files changed

+576
-374
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,7 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
384384
{
385385
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
386386
{
387-
ecma_string_t *name_p = ECMA_GET_POINTER (ecma_string_t, prop_pair_p->names_cp[i]);
388-
389-
ecma_free_property (object_p, name_p, prop_iter_p->types + i);
390-
391-
if (name_p != NULL)
392-
{
393-
ecma_deref_ecma_string (name_p);
394-
}
387+
ecma_free_property (object_p, prop_pair_p->names_cp[i], prop_iter_p->types + i);
395388
}
396389
}
397390

jerry-core/ecma/base/ecma-globals.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ typedef enum
329329
*/
330330
#define ECMA_PROPERTY_FIXED 0
331331

332+
/**
333+
* Shift for property name part.
334+
*/
335+
#define ECMA_PROPERTY_NAME_TYPE_SHIFT (ECMA_PROPERTY_FLAG_SHIFT + 4)
336+
337+
/**
338+
* Property name is a generic string.
339+
*/
340+
#define ECMA_PROPERTY_NAME_TYPE_STRING 3
341+
332342
/**
333343
* Abstract property representation.
334344
*
@@ -411,13 +421,25 @@ typedef struct
411421
#define ECMA_PROPERTY_GET_TYPE(property) \
412422
((ecma_property_types_t) ((property) & ECMA_PROPERTY_TYPE_MASK))
413423

424+
/**
425+
* Get property name type.
426+
*/
427+
#define ECMA_PROPERTY_GET_NAME_TYPE(property) \
428+
((property) >> ECMA_PROPERTY_NAME_TYPE_SHIFT)
429+
414430
/**
415431
* Returns true if the property pointer is a property pair.
416432
*/
417433
#define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) \
418434
(ECMA_PROPERTY_GET_TYPE ((property_header_p)->types[0]) != ECMA_PROPERTY_TYPE_VIRTUAL \
419435
&& (property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
420436

437+
/**
438+
* Returns true if the property is named property.
439+
*/
440+
#define ECMA_PROPERTY_IS_NAMED_PROPERTY(property) \
441+
(ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_SPECIAL)
442+
421443
/**
422444
* Returns the internal property type
423445
*/
@@ -909,14 +931,14 @@ typedef struct
909931
*/
910932
typedef enum
911933
{
912-
ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
913-
* maximum size is 2^16. */
914-
ECMA_STRING_CONTAINER_HEAP_LONG_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
915-
* maximum size is 2^32. */
916934
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
917935
stored locally in the string's descriptor */
918936
ECMA_STRING_CONTAINER_MAGIC_STRING, /**< the ecma-string is equal to one of ECMA magic strings */
919937
ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
938+
ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
939+
* maximum size is 2^16. */
940+
ECMA_STRING_CONTAINER_HEAP_LONG_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
941+
* maximum size is 2^32. */
920942

921943
ECMA_STRING_LITERAL_NUMBER, /**< a literal number which is used solely by the literal storage
922944
* so no string processing function supports this type except
@@ -985,10 +1007,10 @@ typedef struct
9851007

9861008
lit_utf8_size_t long_utf8_string_size; /**< size of this long utf-8 string in bytes */
9871009
uint32_t uint32_number; /**< uint32-represented number placed locally in the descriptor */
988-
lit_magic_string_id_t magic_string_id; /**< identifier of a magic string */
989-
lit_magic_string_ex_id_t magic_string_ex_id; /**< identifier of an external magic string */
1010+
uint32_t magic_string_id; /**< identifier of a magic string */
1011+
uint32_t magic_string_ex_id; /**< identifier of an external magic string */
9901012
ecma_value_t lit_number; /**< literal number (note: not a regular string type) */
991-
uint32_t common_field; /**< for zeroing and comparison in some cases */
1013+
uint32_t common_uint32_field; /**< for zeroing and comparison in some cases */
9921014
} u;
9931015
} ecma_string_t;
9941016

0 commit comments

Comments
 (0)