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

Loader.loadNativeLibraries() taking much longer to run in v9.12 MacOS M1 #4580

Open
ClaudioConsolmagno opened this issue Mar 4, 2025 · 6 comments
Assignees
Labels
Bug Lang: Java Java wrapper issue OS: Mac MacOS
Milestone

Comments

@ClaudioConsolmagno
Copy link

ClaudioConsolmagno commented Mar 4, 2025

What version of OR-Tools and what language are you using?
Version: v9.12
Language: Java

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Not relevant I think but I use ModelBuilder with SCIP

What operating system (Linux, Windows, ...) and version?
MacOS M1
Java corretto 21.0.6 aarch64 (same results on Java 8 and 17)
Have tested on linux and that works fine.

What did you do?
Steps to reproduce the behavior:

plugins {
    id 'java'
}

group = 'dev.claudio'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation('com.google.ortools:ortools-java:9.12.4544')
//    implementation('com.google.ortools:ortools-java:9.11.4210')
}
package dev.claudio;

import com.google.ortools.Loader;

public class Main {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        System.out.println("Started");
        Loader.loadNativeLibraries();
        long timeMs = System.currentTimeMillis() - start;
        System.out.printf("Time taken: %.3f seconds%n", timeMs / 1000.0);
    }
}
  • On v9.12: Time taken: 13.387 seconds
  • On v9.11: Time taken: 0.948 seconds

Anything else we should know about your project / environment
It doesn't seem like there's a lot of CPU usage. I'm not sure how to analyse profiler data:
Image

@lperron
Copy link
Collaborator

lperron commented Mar 4, 2025

does it happen the second time ? I have the same with python binary. The first run is very slow, the second is not.

@ClaudioConsolmagno
Copy link
Author

Once loaded for the first time, Loader.java will immediatelly return. It's not much of a problem in production for us but it is a problem for unit tests and running tests quickly during development.

  /** Unpack and Load the native libraries needed for using ortools-java. */
  private static boolean loaded = false;

  public static synchronized void loadNativeLibraries() {
    // prints the name of the Operating System
    // System.out.println("OS: " + System.getProperty("os.name"));
    if (loaded) {
      return;
    }
   ...
}

@Mizux Mizux added OS: Mac MacOS Lang: Java Java wrapper issue labels Mar 4, 2025
@Mizux Mizux self-assigned this Mar 4, 2025
@Mizux Mizux added the Bug label Mar 4, 2025
@Mizux
Copy link
Collaborator

Mizux commented Mar 4, 2025

we migrate from static libs for deps (with ODR violation) to dynamic libraries...

@Mizux Mizux added this to the v9.13 milestone Mar 4, 2025
@lperron
Copy link
Collaborator

lperron commented Mar 4, 2025

I meant what happens if you run the program twice ? On my python tests, it is very slow the first time, and fast after that.

@lperron
Copy link
Collaborator

lperron commented Mar 4, 2025

maybe an explanation: https://developer.apple.com/forums/thread/655773

@ClaudioConsolmagno
Copy link
Author

On my python tests, it is very slow the first time, and fast after that.

I see. No for me, at least with java with gradle build system, running and re-running have the same effect of ~15s init time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Lang: Java Java wrapper issue OS: Mac MacOS
Projects
None yet
Development

No branches or pull requests

3 participants