| Anonymous | Login | Signup for a new account | 2013-06-20 12:57 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0005779 | OCaml | OCaml backend (code generation) | public | 2012-10-09 15:58 | 2012-12-05 18:22 | ||||||
| Reporter | markghayden | ||||||||||
| Assigned To | |||||||||||
| Priority | normal | Severity | minor | Reproducibility | always | ||||||
| Status | acknowledged | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 4.00.0 | ||||||||||
| Target Version | 4.01.0+dev | Fixed in Version | |||||||||
| Summary | 0005779: static data structures allocated on the GC heap | ||||||||||
| Description | I have fairly large program (120k LOC) with significant amounts of static data structures. For example, large lists of records containing information for rules tables. These are all read-only structures (no mutable records, no arrays). I'd like these in static sections so they don't consume as much memory, have to be allocated and initialized, and incur ongoing overhead from GC scanning them. My software runs on mobile devices (iPads), which can often be quite memory constrained; whatever I can do to reduce memory consumption is helpful. The Ocaml compiler seem to be fairly brittle about determining what should be allocated in static .data sections and what will be allocated and placed on the heap at run time. For example, a simple non-mutable record does is static. A non-mutable record included in a list or another non-mutable record does cause allocation on the heap. It seems references to staticly allocated objects within a second object causes the latter to be allocated on the heap. Can the predicate for what is allocated staticly (not on the heap) be improved to capture a more complete set of cases? Eg ints, strings, floats, lists, non-mutable records, disjoint unions of the preceding. And have that documented? Also, would be nice if these didn't require heap allocation: * Use of modules within files * Declaring an alias of a function at the top level. Eg: let f a = a ;; let g = f ;; | ||||||||||
| Steps To Reproduce | I've attached a short program that declares various structures and monitors which one caused allocation by using Gc.stat. Most of the cases where allocation occurs are avoidable. A few (records with mutable fields) probably require allocation in some cases. I've only compiled the program using native code & for MacOS x64 but I imagine most of this is machine independent. | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | |||||||||||
Notes |
|
|
(0008511) doligez (manager) 2012-11-14 17:36 |
This looks more like a problem with constant propagation: if I inline the names in your examples, almost everything becomes optimal. For example, I replace: let int_alpha_record_record = { alpha = int_alpha_record } ;; with let int_alpha_record_record = { alpha = {alpha = 1} } ;; When I do that for all expressions, the only ones that still allocate are: int_mut_record alloced 2 --- this has to be in the heap because it's mutable int_pairf alloced 3 --- I don't know why inlining doesn't make this one equivalent to int_pair. Of course, my transformation destroys sharing, so you should use it with caution. If you have large immutable data structures that you want to store out of the heap, you should probably have a look at the "ancient" library by Richard Jones: http://git.annexia.org/?p=ocaml-ancient.git;a=summary [^] I hope it still works with the latest versions of OCaml. |
|
(0008570) markghayden (reporter) 2012-12-05 18:22 |
Thanks for the comments. The problem is that I would like to have sharing in these structures. I guess Ancient is a possible approach... but I'd really like to just have the structures allocated as part of the executable. It makes like much simpler. Is there a reason shared structures cannot be allocated statically (not on the heap)? |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2012-10-09 15:58 | markghayden | New Issue | |
| 2012-10-09 15:58 | markghayden | File Added: memory.ml | |
| 2012-11-14 17:36 | doligez | Note Added: 0008511 | |
| 2012-11-14 17:36 | doligez | Status | new => acknowledged |
| 2012-11-14 17:36 | doligez | Target Version | => 4.01.0+dev |
| 2012-12-05 18:22 | markghayden | Note Added: 0008570 | |
| Copyright © 2000 - 2011 MantisBT Group |