Summary: Private module functions optimizations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-08-18 14:20:15 PDT ---
The "private" attribute for module-level functions offers some optimization
opportunities that I think DMD/D-front-end is not using.

Example 1, space optimization: I like the fact that many functions are able to
run both at run-time and compile-time, like some string functions. But I think
that often user-define compile-time functions are never called at run-time. If
such functions are also private, then they can't be called from other modules:

module Foo;
private int sqr(in int x) pure { return x; }
enum y = sqr(10);
void main() {}

In this case I think the compiler is free to not put the implementation of
sqr() into the final binary, saving binary space.


Example 2, performance optimization: if a global function is private, the
compiler is free to change and optimize its signature. An example function:

private void foo(int[] a1, int[] a2) {}
void main() {
    int n = 100; // run-time value
    auto a3 = new int[n];
    auto a4 = new int[n];
    foo(a3, a4);

I think the compiler is free to optimize it into something like this (this is
faster because now the function receives only 3 words instead of 4. If foo()
gets called really many times this is able to make a certain performance

private void foo(int* a1, int* a2, size_t a1a2len) {}
void main() {
    int n = 100;
    auto a3 = new int[n];
    auto a4 = new int[n];
    foo(a3.ptr, a4.ptr, n);

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to