Skip to content

Javascript Helper Mode #5

Description

@csjh

Similar to #1 but more dependent on JS. The goal of it is:

  • Based on the premise that the functions being called aren't the core of the program (ie no or little persistent state), and instead just a fast function/library being swapped in
    • for example, some computation or serde or something
  • Only (heap-based) globals (though they aren't necessary for initial implementation) and returned objects stay on heap
    • note static sized globals are fine, ez implementation
    • everything else is arena allocated and forgotten about (or zeroed) when initial function returns
    • this would probably be done in generated wrapper javascript function
  • pros:
    • fast allocation
    • fast (0 time) deallocation
    • efficient passed back structs
    • convenient, no memory management needed
  • cons:
    • if allocating in a loop or something repeatedly, arena usage could grow very fast, and free'ing would be weird without a bunch more complexity
      • look into how others do it
        • is tight malloc/free even a common thing though? more probable it would happen on the stack
  • things to think about:
    • how should heap memory work? only globals would access it, but if that's forbidden, then it would allow very nice(?) memory layout of [static | stack | <objects in jsland, expands forward, basic linkedlist to figure out position(?)> | empty space | arena, expands down]
      • how does arena work when memory.grow? memcpy?
    • objects in jsland optimized malloc:
      • first: (15 bit?) enumeration of all sizeof(struct)s
      • then: [16 bit free status + enumeration, sizeof(struct)]
      • malloc iterates thru based on sizeof(), looking for big enough free chunk

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions