#Can you make the "sub modules" in build.zig use release-fast

1 messages ยท Page 1 of 1 (latest)

limpid smelt
#

How do you make the seperate packages you pull into your project run with release-fast even when your overall project is still under development/debug progress. Is it to do with the optimize setting? Am I on the right track, or does that not even make sense?

(I have some dependent packages that run quite slow when not using release fast, and it just slows down my parent project signifcantly.)

muted zodiac
#

I think you can just set the .optimize to what you want

limpid smelt
#

So two different optimize variables, one for the main project and one for the children. That seems to make sense to me.

#

Just need to work out how to code that ๐Ÿ™‚

muted zodiac
#

well, not even that, just

const child = b.createModule(.{
  .optimize = .ReleaseFast
};
#

since .optimize is just an enum anyway, if you want to hardcode it, just hardcode it, no need to create an option for it

limpid smelt
#

Oh, thats easier than I thought. I thought that field would have been some complex set of flags

#

its just " std.builtin.OptimizeMode.ReleaseFast"

muted zodiac
#

yup

delicate veldt
#

in case of dependency it's

const your_dep = b.dependency("your_dep", .{
    .optimise = .Release, // or .ReleaseFast if you dare
}):
limpid smelt
#

Thanks! much appreciated. This is going to fix my build times significantly.

#

Yea its a 1 second startup, its going to be .ReleaseFast ๐Ÿ™‚

#

gets it down to 0.1s

delicate veldt
#

Try it with release first, maybe similar performance but don't lose safety

limpid smelt
#

oh, ok, will do. Thanks

muted zodiac
#

I'd would be surprised if you gain that much time just by switching from Release to ReleaseFast

limpid smelt
#

Ill test, thanks

delicate veldt
#

ReleaseFast means "screw every safety check, full speed mode"
So stuff like unreachable become undefined behaviour and bounds checks disappear

muted zodiac
#

since ReleaseFast disables lots of safety but I don't think it improves the runtime that much

limpid smelt
#

Its loading and indexing a 1 million record data file.

delicate veldt
#

it can, but usually recommended only when you're fine with stuff silently breaking or if you have tested it throroughly. Probably safer to set releasefast at function level

muted zodiac
delicate veldt
#

since it's external project, i'd leave it on Release

muted zodiac
limpid smelt
#

Maybe it doesnt work like we guess, its taking 6 seconds to startup still.

#

const praxis = b.dependency("praxis", .{
.optimize = .ReleaseFast,
});
const praxis_module = praxis.module("praxis");

#

Maybe its not possible to make the submodules build with a different profile

muted zodiac
#

it is, it doesn't make sense otherwise

#

what's the errror message?

limpid smelt
#

oh, no error, ....

muted zodiac
#

ah, it's just slower, lol

#

Windows?

limpid smelt
#

debug: Sorting dictionary indexes.
debug: Loaded dictionary.
debug: load dictionary: 6859ms. load resources: 1135ms
load dictionary: 6859ms.
load resources: 1135ms

#

It woudnt take that long if it was release mode

delicate veldt
#

check the dependency's build.zig, maybe it doesnt add standard build flags

limpid smelt
#

I'll check.

#

lol, the dependencies build.zig hardcodes .ReleaseFast I must have gotten sick of it being crazy slow.

    _ = b.addModule("praxis", .{
        .root_source_file = b.path("src/praxis.zig"),
        .target = target,
        //.optimize = optimize,
        .optimize = .ReleaseFast,
    });

    const exe = b.addExecutable(.{
        .name = "praxis",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = .ReleaseFast,
        .strip = true,
    });
elfin light
#

modules having different optimize modes isnt currently very useful, all it changes is the safety

delicate veldt
#

lol, so it is releasefast by default. Oh well, get faster storage or test with smaller data set

limpid smelt
#

Ok, thanks, I did wonder if having different optimize modes made sense at all.

#

I suppose if the dependency was split off as a seperately linked lib file it might work?

delicate veldt
#

You can put data file in /tmp if you have it mounted as RAM FS, should be faster to read as long as you have enough memory to spare

#

Ofc should copy it there not move to tmp

limpid smelt
#

Thanks, good idea. I'll think of a way to reduce it. ( I do like developing with the full ldata set, but the build/run cycle is too long. )

delicate veldt
limpid smelt
#

For now I think I'll just dev with zig build run --release=fast That gets me down from. 7 second startup back down to 1 second. ๐Ÿ™‚

delicate veldt
#

Huh, that sounds like an old zig, right now it's -Doptimize=ReleaseFast

delicate veldt
limpid smelt
#

Its the optomize setting that gets the dependency almost 10 times faster.

#

The dependency is a generic "dictionary/data load/search" type project. The parent is an sdl3 project.

#

The dependency is slowing down the parent sdl3 project I am developing

delicate veldt
#

Then it does seem to be set to ReleaseFast and native target. If it's a C project, maybe it requires some specific defines for some perf features?

limpid smelt
#

Its just zig pulling in zig...

#

The parent project just does this...

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const praxis = b.dependency("praxis", .{
        .optimize = .ReleaseFast,
    });
    const praxis_module = praxis.module("praxis");

    ...
    const exe_mod = b.createModule(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
        .imports = &.{
            .{ .name = "sdl", .module = sdl_mod },
            .{ .name = "praxis", .module = praxis_module },
        },
    });

delicate veldt
#

Hm, just in case add .target = target to praxis dependency

limpid smelt
#

Thanks, I'll try

delicate veldt
limpid smelt
limpid smelt
delicate veldt
#

Well idk, compilation wise it seems like it does get full optimisation. Maybe the bottleneck is elsewhere, if you know that the lib should be faster in some other context

limpid smelt
#

If this is right, then it seems like we cant yet optimize modules with different levels of optimisation.

delicate veldt
#

not sure, i don't think it would ignore the module's explicit .target param. Would have to inspect source to be for sure.

Alternative would be to compile it as seperate static library, but then you're constrained to C API instead of zig module API

limpid smelt
#

Yea. I like your idea to just reduce the data set for now.

#

That will get me going ๐Ÿ™‚ Thanks for the feedback though.

#

I kind of hate playing with build.zig. As powerful as it is (and it is great), I still dont compelety understand it ๐Ÿ™‚

delicate veldt
#

i guess it makes sense that modules get same optimisation, it probably gets compiled all in one pass since it's zig modules all the way down

limpid smelt
#

Yea, maybe the setting gets applied later on in the build process.

delicate veldt
#

I mostly stick to exploring Build.zig, it starts to make sense what steps it can create and how they can be linked