From 30827b038331d913b1b5561e06bd61b7f1824947 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 10 Dec 2023 21:40:36 -0500 Subject: [PATCH 1/2] perf: optimize OpamString.split this cuts the time spent on parsing `pacman -Si` significantly down Co-authored-by: Kate --- master_changes.md | 1 + src/core/opamStd.ml | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/master_changes.md b/master_changes.md index f5a6340d329..712fd68f77b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -200,6 +200,7 @@ users) * `OpamFile.Repos_config.t`: change the type to not allow repositories without an URL [#6249 @kit-ty-kate] ## opam-core + * `OpamStd.List.split`: Improve performance [#6210 @kit-ty-kate] * `OpamStd.Sys.{get_terminal_columns,uname,getconf,guess_shell_compat}`: Harden the process calls to account for failures [#6230 @kit-ty-kate - fix #6215] * `OpamStd.Sys.getconf`: was removed, replaced by `get_long_bit` [#6217 @kit-ty-kate] * `OpamStd.Sys.get_long_bit`: was added, which returns the output of the `getconf LONG_BIT` command [#6217 @kit-ty-kate] diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index 226af7effb3..2b766533742 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -692,9 +692,25 @@ module OpamString = struct let rcut_at = cut_at_aux String.rindex let split s c = - (* old compat version (Re 1.2.0) - {[Re_str.split (Re_str.regexp (Printf.sprintf "[%c]+" c)) s]} *) - Re.(split (compile (rep1 (char c)))) s + let rec loop acc i slice_start len s c = + if (i : int) < (len : int) then + if s.[i] = (c : char) then + let acc = + if (slice_start : int) < (i : int) then + String.sub s slice_start (i - slice_start) :: acc + else + acc + in + let i = i+1 in + loop acc i i len s c + else + loop acc (i+1) slice_start len s c + else if (i : int) = (slice_start : int) then + acc + else + String.sub s slice_start (len - slice_start) :: acc + in + List.rev (loop [] 0 0 (String.length s) s c) let split_delim s c = let tokens = Re.(split_full (compile (char c)) s) in @@ -1160,9 +1176,9 @@ module OpamSys = struct | SH_fish -> Some (List.fold_left Filename.concat (home ".config") ["fish"; "config.fish"]) | SH_zsh -> - let zsh_home f = + let zsh_home f = try Filename.concat (Env.get "ZDOTDIR") f - with Not_found -> home f in + with Not_found -> home f in Some (zsh_home ".zshrc") | SH_bash -> let shell = From 9002d47c1d95e303337c21fa42b3ae326c47b6dd Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 17 Dec 2024 14:23:37 +0000 Subject: [PATCH 2/2] GHA: Fix CI by disabling apparmor See https://github.com/actions/runner-images/issues/10015 and https://github.com/ocaml/opam/issues/5968 --- .github/workflows/ci.ml | 6 ++++++ .github/workflows/main.yml | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/ci.ml b/.github/workflows/ci.ml index e9841e2805b..0460a4fd719 100644 --- a/.github/workflows/ci.ml +++ b/.github/workflows/ci.ml @@ -333,6 +333,7 @@ let main_build_job ~analyse_job ~cygwin_job ?section runner start_version ~oc ~w let host = host_of_platform platform in job ~oc ~workflow ~runs_on:(Runner [runner]) ?shell ?section ~needs ~matrix ("Build-" ^ name_of_platform platform) ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ only_on Windows (git_lf_checkouts ~cond:(Predicate(true, EndsWith("matrix.host", "-pc-cygwin"))) ~shell:"cmd" ~title:"Configure LF checkout for Cygwin" ()) ++ checkout () ++ only_on Windows (cache ~cond:(Predicate(true, Compare("matrix.build", "x86_64-pc-cygwin"))) Cygwin) @@ -384,6 +385,7 @@ let main_test_job ~analyse_job ~build_linux_job ~build_windows_job:_ ~build_macO ++ only_on MacOS (install_sys_packages ["coreutils"; "gpatch"] ~descr:"Install gnu coreutils" [MacOS]) ++ checkout () ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ cache Archives ++ cache OCaml platform ocamlv host ++ build_cache OCaml platform ocamlv host @@ -402,6 +404,7 @@ let cold_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ? let needs = [analyse_job; (match platform with Linux -> build_linux_job | Windows -> build_windows_job | MacOS -> build_macOS_job)] in job ~oc ~workflow ?section ~runs_on:(Runner [runner]) ~env:[("OPAM_COLD", "1")] ~needs ("Cold-" ^ name_of_platform platform) ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ checkout () ++ cache Archives ++ run "Cold" [ @@ -420,6 +423,7 @@ let doc_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ?s let ocamlv = "${{ matrix.ocamlv }}" in job ~oc ~workflow ?section ~runs_on:(Runner [platform]) ~env ~needs ~matrix ("Doc-" ^ name_of_platform platform) ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ run "Install man2html" ["sudo apt install man2html"] ++ checkout () ++ cache Archives @@ -444,6 +448,7 @@ let solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_jo let ocamlv = "${{ matrix.ocamlv }}" in job ~oc ~workflow ?section ~runs_on:(Runner [runner]) ~env ~needs ~matrix ("Solvers-" ^ name_of_platform platform) ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ checkout () ++ cache Archives ++ cache OCaml platform ocamlv host @@ -463,6 +468,7 @@ let upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_jo let ocamlv = "${{ matrix.ocamlv }}" in job ~oc ~workflow ?section ~runs_on:(Runner [runner]) ~needs ~matrix ("Upgrade-" ^ name_of_platform platform) ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) ++ checkout () ++ cache Opam12Root ++ cache OCaml platform ocamlv host diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1805175afd0..8ab6c608398 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -111,6 +111,8 @@ jobs: steps: - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Checkout tree uses: actions/checkout@v4 - name: src_ext/archives and opam-repository Cache @@ -288,6 +290,8 @@ jobs: uses: actions/checkout@v4 - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: src_ext/archives and opam-repository Cache id: archives uses: actions/cache@v4 @@ -394,6 +398,8 @@ jobs: steps: - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Checkout tree uses: actions/checkout@v4 - name: src_ext/archives and opam-repository Cache @@ -427,6 +433,8 @@ jobs: steps: - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Install man2html run: sudo apt install man2html - name: Checkout tree @@ -483,6 +491,8 @@ jobs: steps: - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Checkout tree uses: actions/checkout@v4 - name: src_ext/archives and opam-repository Cache @@ -576,6 +586,8 @@ jobs: steps: - name: Install bubblewrap run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Checkout tree uses: actions/checkout@v4 - name: opam 1.2 root Cache