Comments (7)
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.
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.
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 theprogram->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.
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.
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.
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.
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)
- try to AOT
- Compilation error when exporting c++ class with ManagedStructureAnnotation
- How to debug in an embedded environment using VSCode ? HOT 1
- cmake error ~~ help~~
- Which should I use “addExtern” or “addInterop”? HOT 1
- Unexpected execution when embedded module, Executed without being called~~ HOT 1
- No Garbage collection ? HOT 3
- where is libclang HOT 2
- 30304: function not found HOT 5
- How to correctly require the parent module or somewhere ? HOT 2
- How to export a array<c++ struct> to das ? HOT 3
- How to generate .wasm HOT 2
- How to list exported symbols from modules HOT 2
- Bad floating point comparisons HOT 9
- Arrays
- Optimizing related_post_gen benchmark HOT 12
- null pointer passed as argument HOT 1
- It is recommended that compiled binaries be released for download.
- Compilation error using static linking HOT 1
- Is it possible to define a single module across multiple files? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dascript.