Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rdmd runs dmd twice for single-files with no dependencies #413

Open
dlang-bugzilla-migration opened this issue Jun 5, 2020 · 0 comments
Labels
Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd Type.Enhancement An improvement to an existing functionality

Comments

@dlang-bugzilla-migration

Transferred from: https://issues.dlang.org/show_bug.cgi?id=16431

User @wilzbach reported (2016-Aug-25 20:50:41):

$ python -m timeit -v -n 10 -s 'import os' 'os.system("dub run --single --force foo.d")'
10 loops, best of 3: 578 msec per loop
$ python -m timeit -v -n 10 -s 'import os' 'os.system("rdmd --force foo.d")'
10 loops, best of 3: 730 msec per loop

I used an example from the DLang Tour (see below or http://tour.dlang.io/tour/en/gems/template-meta-programming) and tested with more and the overhead seems to stay there:

== Associative arrays ==

http://tour.dlang.io/tour/en/basics/associative-arrays

rdmd 5 loops, best of 3: 637 msec per loop
dub: 5 loops, best of 3: 584 msec per loop

== Loops ==

http://tour.dlang.io/tour/en/basics/loops

rdmd: 5 loops, best of 3: 488 msec per loop
dub: 5 loops, best of 3: 373 msec per loop
#!/usr/bin/env rdmd
/+ dub.sdl:
name "foo"
+/

import std.traits: isFloatingPoint;
import std.uni: toUpper;
import std.string: format;
import std.stdio: writeln;

/// A Vector that just works for
/// numbers, integers or floating points.
struct Vector3(T)
  if (is(T: real))
{
private:
    T x,y,z;

    /// Generator for getter and setter because
    /// we really hate boiler plate!
    ///
    /// var -> T getVAR() and void setVAR(T)
    mixin template GetterSetter(string var) {
        // Use mixin to construct function
        // names
        mixin("T get%s() const { return %s; }"
          .format(var.toUpper, var));

        mixin("void set%s(T v) { %s = v; }"
          .format(var.toUpper, var));
    }

    // Easily generate our getX, setX etc.
    // functions with a mixin template.
    mixin GetterSetter!"x";
    mixin GetterSetter!"y";
    mixin GetterSetter!"z";

public:
    // We don't allow the dot function
    // for anything but floating points
    static if (isFloatingPoint!T) {
        T dot(Vector3!T rhs) {
            return x*rhs.x + y*rhs.y +
                z*rhs.z;
        }
    }
}

void main()
{
    auto vec = Vector3!double(3,3,3);
    // That doesn't work because of the template
    // constraint!
    // Vector3!string illegal;

    auto vec2 = Vector3!double(4,4,4);
    writeln("vec dot vec2 = ", vec.dot(vec2));

    auto vecInt = Vector3!int(1,2,3);
    // doesn't have the function dot because
    // we statically enabled it only for float's
    // vecInt.dot(Vector3!int(0,0,0));

    // generated getter and setters!
    vecInt.setX(3);
    vecInt.setZ(1);
    writeln(vecInt.getX, ",",
      vecInt.getY, ",", vecInt.getZ);
}

User @aG0aep6G responded (2016-Aug-25 21:26:33):

I don't think this is much of a surprise. rdmd detects dependencies. dub doesn't seem to do that.

User @wilzbach responded (2016-Aug-26 02:00:56):

I don't think this is much of a surprise. rdmd detects dependencies. dub doesn't seem to do that.

Well, it still seems unnecessary to me to run the full-blown CTFE compiler twice on a file. I gave it a quick try with two hacks:

#191

User @aG0aep6G responded (2016-Aug-26 13:08:02):

(In reply to greensunny12 from comment 2)

Well, it still seems unnecessary to me to run the full-blown CTFE compiler
twice on a file.

Sure. If you make rdmd faster, that's great. I just don't think that dub has anything to do with it.

User @AndrejMitrovic responded (2016-Aug-31 21:30:26):

Fixed right? Closing.

User @wilzbach responded (2017-Jul-20 20:07:38):

PR was reverted :/

User @marler8997 responded (2017-Dec-14 16:37:33):

Potential fix: #271
"Use "-i" to prevent rdmd from having to invoke compiler twice."

Depends on this first: dlang/dmd#7099
"Enable automatic compiling of imports"

User @marler8997 responded (2018-Jan-17 02:39:18):

#271

User @marler8997 responded (2018-Jan-20 02:21:14):

#271 was reverted

@dlang-bugzilla-migration dlang-bugzilla-migration added Type.Enhancement An improvement to an existing functionality Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd labels Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd Type.Enhancement An improvement to an existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant