﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3814	Optimizsation of record modifications	Henning Kiel	Martin Sjölund	"Consider the following example code:

{{{
record exampleLst
  Integer n;
  list<Integer> elems;
  // more elements to follow...
end record;

function appList
  input list<Integer> li;
  input output exampleLst lst;
algorithm
    lst.n := lst.n + listLength(li);
    lst.elems := listAppend(li, lst.elems);
  end with;
end appList;
}}}

Currently the compiler will create a new record for each of the two assignment lines (via {{{mmc_mk_box()}}}), though the intermediate object is never really referenced or used.

Now, the compiler could try to figure out this and only do one {{{mmc_mk_box()}}} incorporating both changes. This would immediately reduce overall memory usage.

A second approach would be to extend MetaModelica language with a {{{with <elem> do … end with;}}} construct like the following:

{{{
function appList
  input list<Integer> li;
  input output exampleLst lst;
algorithm
  with lst do
    .n := .n + listLength(li);
    .elems := listAppend(.elems, li);
  end with;
end appList;
}}}

Here, the assignment ({{{mmc_mk_box()}}}) is only done at the {{{end with;}}} line, and the component contents stored in temporary variables.

I do not bother if one or both ways are implemented, but I would definitely love to see at least one of them :-)

The second approach could also be extended to e.g. also allow for-loops etc.

{{{
function appList
  input list<list<Integer>> lists;
  input output exampleLst lst;
algorithm
  for li in lists loop
    with lst do
      .n := .n + listLength(li);
      .elems := listAppend(.elems, li);
     end with;
  end for;
end appList;
}}}"	enhancement	new	high	Future	MetaModelica				Francesco Casella
