www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Speeding up program loading

reply bearophile <bearophileHUGS lycos.com> writes:
Once people write large programs with D2, such experiments can become useful.
This is the last blog post of a short series where they try to speed up Mozilla
startup:
http://blog.mozilla.com/tglek/2010/05/27/startup-backward-constructors/

More about similar topics, older posts from the same blog:
http://blog.mozilla.com/tglek/2010/04/

Bye,
bearophile
Jun 18 2010
parent reply Walter Bright <newshound1 digitalmars.com> writes:
bearophile wrote:
 Once people write large programs with D2, such experiments can become useful.
This is the last blog post of a short series where they try to speed up Mozilla
startup:
 http://blog.mozilla.com/tglek/2010/05/27/startup-backward-constructors/
 
 More about similar topics, older posts from the same blog:
 http://blog.mozilla.com/tglek/2010/04/
This stuff has been well understood since at least the late 1980's, and is perpetually forgotten and rediscovered. The "Segmentor" was a product (now forgotten) that would optimize your windows code layout for fast loading 20 years ago. I know that Microsoft uses similar technology. Mozilla is way, way behind. The Digital Mars linker can accept linker scripts http://www.digitalmars.com/ctg/ctgDefFiles.html where the layout of the functions can be specified in the FUNCTIONS section. It's a pain to do this manually, so the profiler http://www.digitalmars.com/ctg/trace.html will use runtime profiling to generate this script. It works for dmd, too. I've worked out a design for the front end to do this automatically based on static analysis, but haven't implemented it yet.
Jun 18 2010
parent reply Moritz Warning <moritzwarning web.de> writes:
Hi,

I need to call a C function from D.
No problem so far, but here is the catch:
The function signature is only known at runtime.

There is the void* pointer to the C-function
and void* pointers to the argument values + value size.

Now I need to build up the call stack myself.
How can it be done (maybe without assembler?).


Here is a first try, but D puts the length and pointer of part2
onto the stack as well.

uint part1; //C vararg functions need a least one fixed argument
ubyte[64] part2;

...

auto fp = cast(extern(C) void(uint x, ...)) func_ptr;
fp(part1, part2);
Jun 20 2010
parent novive2 <sorry noem.ail> writes:
Moritz Warning Wrote:
 Now I need to build up the call stack myself.
dmd\src\phobos\std\c\stdio.d contain printf() declaration. it vararg. so, imho, you can declare and call C func with varargs. May be you don't need to construct call stack, but properly declare C func?
Jun 20 2010