aggregating string constant/identifiers
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 431
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
right now all strings constants (including identifiers) are created in the .data segment of the resulting executable. that way we don't pay any heap cost for their usage (yay.)
This mostly works, but there are a couple of problems with the approach:
- they're not aggregated across different .js files - each .js file gets its own string constants. I haven't measured how much duplication we have, but switching to es6 modules with each file in the bindings (115+ in UIKit) having their own strings.. I expect we could be saving some memory.
- They have a startup cost associated with them - or rather a toplevel func invocation cost. This is because we need them to be represented as ejsvals. so we generate three globals in llvm IR during compilation - an
ejsvalfor the actual value we'll be using for a given constant, anEJSPrimString, and a ucs2 buffer. The initialization of a given constant string looks something like:
ejs_prim_string_%1235.length = <compile-time-known-constant>;
ejs_prim_string_%1235.data.flat = ucs2_buffer_%1235;
ejsval_%1235 = STRING_TO_EJSVAL_IMPL(&ejs_prim_string_%1235);
it would be lovely if we could use relocs + other magic to have all this happen at link time.
Fixing 1 up there is as easy as just keeping a map during compilation and spitting out the right stuff after we've processed all the .js, similar to what we do for the require map. We could even spit it out as a .c file like the require map.. maybe the C compiler will do a better job of linking everything together without requiring runtime initialization.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how string constants are generated for each .js file and compare that path with the existing require map. Determine whether a shared generated C file can consolidate constants and whether link-time initialization can address the startup cost; done requires an agreed design and measurements for both duplication and initialization overhead.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, javascript
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100