Giter Club home page Giter Club logo

Comments (7)

borisbat avatar borisbat commented on May 31, 2024

most likely context is using 0GC, and not persistent heap
i.e u need
options persistent_heap = true
options persistent_string_heap = true

from dascript.

borisbat avatar borisbat commented on May 31, 2024

on the similar note - its a lot faster to use 0GC and reset context, than to use persistent GC and collect
also likely mark\sweep should not be called every time

lastly, external function does not have to allocate string on our heap. it can return temporary value, or, better yet invoke a block, where temporary value is a parameter. string peek is an example of such function

from dascript.

ihm-tswow avatar ihm-tswow commented on May 31, 2024

Thanks!

By using this at the top of my script:

options persistent_heap = true
options persistent_string_heap = true

and by invoking the gc via ctx->collectStringHeap(nullptr) instead of mark/sweep it seems I am able to correctly hold on to string references in the global scope without leaking.

Remaining issues

  • I couldn't find a similar function that worked for the normal heap. Can I do this with non-strings? It looks like mark always returns false for other allocators.

  • Can I force these options (persistent_heap etc) for a program from the C++ side? I'm guessing it's the program->options vector, do I just fill that up with values somehow? (fix below)

(second comment)

I'm just cleaning it every time to debug it for now, I'll probably use ctx->stringHeap->bytesAllocated along with some counter for when to invoke it in production, but GC cost isn't very important for our tool. We're using daScript in a map editor, so we would like to allow scripters to store large strings, images and noisemaps in the global scope between events:

var big_image = empty_image();

[export]
def left_click()
    if(!is_loaded(big_image))
        load_image(big_image,"some/image/path.png");
    ....

from dascript.

ihm-tswow avatar ihm-tswow commented on May 31, 2024

Looks like I can do this to set default options from C++:

auto program = compileDaScript(....);

// do this right after compiling the program, before simulating.
if (!program->options.find("persistent_heap",das::Type::tBool))
{
    program->options.push_back(AnnotationArgument("persistent_heap",true));
}

if (!program->options.find("persistent_string_heap",das::Type::tBool))
{
    program->options.push_back(AnnotationArgument("persistent_string_heap",true));
}

// use this selectively if you don't want to accidentally intern arbitrary data.
if(!program->options.find("intern_strings",das::Type::tBool))
{
    program->options.push_back(AnnotationArgument("intern_strings",false));
}

from dascript.

borisbat avatar borisbat commented on May 31, 2024

CodeOfPolicies has those settings explicitly. I.e.

    struct CodeOfPolicies {
...
        uint32_t    stack = 16*1024;                    // 0 for unique stack
        bool        intern_strings = false;             // use string interning lookup for regular string heap
        bool        persistent_heap = false;
        uint32_t    heap_size_hint = 65536;
        uint32_t    string_heap_size_hint = 65536;
...

from dascript.

borisbat avatar borisbat commented on May 31, 2024

There is version of collect for normal heap, which will be merged in eventually. However it is significantly more robust to use 0-GC, or, explicitly call 'delete' for large structures.

from dascript.

ihm-tswow avatar ihm-tswow commented on May 31, 2024

Neat, and thanks. I tried accessing CodeOfPolicies before, but it didn't seem to affect the string heap (?), I can try it again now that the rest is working. Great to hear it's getting merged, until then we'll use manual deallocators (or with how good our tests have gone, I might attempt to hack the string heap).

This resolves all my issues, thank you so much for the help!

from dascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.