API support for dealing with interned strings directly
See original GitHub issueWhen C code operates on object properties a C string is passed in (usually a literal but can also be a dynamic input). All such operations will be slowed down by the need to intern the string.
Internally property operations are ultimately always performed using interned strings (duk_hstring *) and since it’s already possible to get a borrowed reference to a heap object, interned strings can already be used for property accesses e.g. as:
duk_push_heapptr(ctx, my_string_ref);
duk_get_prop(ctx, obj_idx);
It would be nice to improve that to e.g.:
duk_get_prop_heapptr(ctx, my_string_ref);
This could be implemented a bit faster internally because the unnecessary value stack push can be avoided.
Naturally there are many API variations, like:
- Instead of using the generic
duk_get_heapptr()provide a dedicated API call to intern a string. - For long lived strings it might be useful to be able to
void *mystr = duk_something(ctx, "my_key");which would store a stash (or other persistent) reference so that you wouldn’t need to worry about string reachability.
But as an initial step, being able to use a borrowed key reference more directly would be easiest.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:45 (44 by maintainers)
Top Results From Across the Web
Developers - API support for dealing with interned strings directly -
When C code operates on object properties a C string is passed in (usually a literal but can also be a dynamic input)....
Read more >The zend_string API - PHP Internals Book
Interned strings are deduplicated strings. When used with opcache, they also get reused from request to request. Say you want to create the...
Read more >Is it good practice to use java.lang.String.intern()?
The best place to do the interning is usually when you are reading keys that are stored outside of the code as strings...
Read more >Hidden Reefs in String Pool, or Another Reason to Think ...
One of these optimization techniques is the so-called string interning. It allows users to reduce memory usage. It also makes string ...
Read more >String.Intern(String) Method (System) - Microsoft Learn
The Intern method uses the intern pool to search for a string equal to the value of str . If such a string...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, there’s no difference from the internals point of view.
Oh, I agree 100%. If it weren’t for Duktape, Spherical still wouldn’t have a modern engine, so I’m glad you released it 😃