question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API support for dealing with interned strings directly

See original GitHub issue

When 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:open
  • Created 7 years ago
  • Reactions:2
  • Comments:45 (44 by maintainers)

github_iconTop GitHub Comments

1reaction
svaaralacommented, Jan 17, 2017

Yes, there’s no difference from the internals point of view.

1reaction
fatcerberuscommented, Jan 17, 2017

I thought it more important to achieve a functional 1.0.0 rather than keep on rewriting the building blocks over and over for performance (which is also important, but having a baseline release is maybe more important).

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found