Skip to content

Performance on strings #19

@simsurace

Description

@simsurace

Somewhere along the way performance on strings must have taken a hit:

julia> data = rand(UInt8, 10^6);

julia> str = String(data);

julia> @time md5(data);
  0.000047 seconds (6 allocations: 288 bytes)

julia> @time md5(str);
  2.112903 seconds (6 allocations: 288 bytes)

julia> versioninfo()
Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 12 × Apple M3 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 4 default, 0 interactive, 2 GC (on 6 virtual cores)
Environment:
  JULIA_CONDAPKG_BACKEND = Null
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1
  JULIA_NUM_THREADS = 4

Is there an easy fix? Even md5(collect(codeunits(str))) would be way better than this:

julia> @time md5(collect(codeunits(str)));
  0.002464 seconds (10 allocations: 992.359 KiB)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions