<p dir="auto">The definition of <code class="notranslate">argmax</code> from <a href="https://en.wikipedia.org/wiki/Arg_max" rel="nofollow">Wikipedia</a>,<br>
Given a collection of elements (domain), which map to an ordered set (range), what is the subset containing those elements in the domain whose image is the frontier.</p>
<p dir="auto">Currently, <code class="notranslate">argmax</code> is actually <code class="notranslate">indmax</code> which is defined for indexed collections and returns the index of the first encountered element whose image is equal to the frontier. The generalization of <code class="notranslate">keymax</code> (discussed, but not implemented) extends the supported collections from indexed to <code class="notranslate">pairs</code>-implemented collections. This is the result of renaming <code class="notranslate">indmax</code> to <code class="notranslate">argmax</code>. A current proposal is for <code class="notranslate">argmax</code> to be defined for <code class="notranslate">Generator</code> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="333000377" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/27613" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/27613/hovercard" href="https://github.com/JuliaLang/julia/issues/27613">#27613</a>),</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="argmax(f(x) for x ∈ domain)"><pre class="notranslate"><code class="notranslate">argmax(f(x) for x ∈ domain)
</code></pre></div>
<p dir="auto">with that change, we could fix the implementation with something like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import Base: Generator, argmax
function argmax(f::Function, domain::Generator)
    T = eltype(domain)
    tested = Set{T}()
    output = Set{T}()
    frontier = nothing
    for elem ∈ domain
        if !(elem ∈ tested)
            push!(tested, elem)
            value = f(elem)
            if (frontier === nothing) || (value &gt; frontier)
                frontier = value
                output = Set(elem)
            elseif value == frontier
                push!(output, elem)
            end
        end
    end
    return output
end"><pre class="notranslate"><code class="notranslate">import Base: Generator, argmax
function argmax(f::Function, domain::Generator)
    T = eltype(domain)
    tested = Set{T}()
    output = Set{T}()
    frontier = nothing
    for elem ∈ domain
        if !(elem ∈ tested)
            push!(tested, elem)
            value = f(elem)
            if (frontier === nothing) || (value &gt; frontier)
                frontier = value
                output = Set(elem)
            elseif value == frontier
                push!(output, elem)
            end
        end
    end
    return output
end
</code></pre></div>
<p dir="auto">and call it with the following syntax</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="argmax(abs2, elem for elem ∈ -3:3) == Set([-3, 3])"><pre class="notranslate"><code class="notranslate">argmax(abs2, elem for elem ∈ -3:3) == Set([-3, 3])
</code></pre></div>
<p dir="auto">From <a href="https://discourse.julialang.org/t/serialization-serialize-strings-are-not-interned-de-duplication/35626" rel="nofollow">https://discourse.julialang.org/t/serialization-serialize-strings-are-not-interned-de-duplication/35626</a></p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vtjnash/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vtjnash">@vtjnash</a> asked me to open this as an Issue on the repo. Can we implement string interning when serializing (large) strings? Can we maybe share this logic with the interning for Symbols? Thanks!</p>
<p dir="auto">--<br>
Copied from discourse:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; using Humanize  # For pretty printing, not necessary for reproduction

julia&gt; using Serialization

julia&gt; struct StringHolder
           a::String
           b::String
       end

julia&gt; s = join(rand('a':'z', 1024*1024)); # 1 MiB string

julia&gt; sh = StringHolder(s, s);

julia&gt; Humanize.datasize(Base.summarysize(sh), style=:bin)  # The string is shared in memory.
&quot;1.0 MiB&quot;

julia&gt; serialize(&quot;/tmp/sh&quot;, sh)

julia&gt; run(`ls -lh /tmp/sh`)  # Size on disk is 2 MiB! (duplicated!)
-rw-r--r--  1 nathan.daly  wheel   2.0M Mar  6 00:06 /tmp/sh
Process(`ls -lh /tmp/sh`, ProcessExited(0))

julia&gt; sh_deserialized = deserialize(&quot;/tmp/sh&quot;);   # It's big now! :'(

julia&gt; Humanize.datasize(Base.summarysize(sh_deserialized), style=:bin)
&quot;2.0 MiB&quot;"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">using</span> Humanize  <span class="pl-c"><span class="pl-c">#</span> For pretty printing, not necessary for reproduction</span>

julia<span class="pl-k">&gt;</span> <span class="pl-k">using</span> Serialization

julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> StringHolder
           a<span class="pl-k">::</span><span class="pl-c1">String</span>
           b<span class="pl-k">::</span><span class="pl-c1">String</span>
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> s <span class="pl-k">=</span> <span class="pl-c1">join</span>(<span class="pl-c1">rand</span>(<span class="pl-s"><span class="pl-pds">'</span>a<span class="pl-pds">'</span></span>:<span class="pl-s"><span class="pl-pds">'</span>z<span class="pl-pds">'</span></span>, <span class="pl-c1">1024</span><span class="pl-k">*</span><span class="pl-c1">1024</span>)); <span class="pl-c"><span class="pl-c">#</span> 1 MiB string</span>

julia<span class="pl-k">&gt;</span> sh <span class="pl-k">=</span> <span class="pl-c1">StringHolder</span>(s, s);

julia<span class="pl-k">&gt;</span> Humanize<span class="pl-k">.</span><span class="pl-c1">datasize</span>(Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>(sh), style<span class="pl-k">=</span><span class="pl-c1">:bin</span>)  <span class="pl-c"><span class="pl-c">#</span> The string is shared in memory.</span>
<span class="pl-s"><span class="pl-pds">"</span>1.0 MiB<span class="pl-pds">"</span></span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">serialize</span>(<span class="pl-s"><span class="pl-pds">"</span>/tmp/sh<span class="pl-pds">"</span></span>, sh)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">run</span>(<span class="pl-s"><span class="pl-pds">`</span>ls -lh /tmp/sh<span class="pl-pds">`</span></span>)  <span class="pl-c"><span class="pl-c">#</span> Size on disk is 2 MiB! (duplicated!)</span>
<span class="pl-k">-</span>rw<span class="pl-k">-</span>r<span class="pl-k">--</span>r<span class="pl-k">--</span>  <span class="pl-c1">1</span> nathan<span class="pl-k">.</span>daly  wheel   <span class="pl-c1">2.0</span>M Mar  <span class="pl-c1">6</span> <span class="pl-c1">00</span><span class="pl-k">:</span><span class="pl-c1">06</span> <span class="pl-k">/</span>tmp<span class="pl-k">/</span>sh
<span class="pl-c1">Process</span>(<span class="pl-s"><span class="pl-pds">`</span>ls -lh /tmp/sh<span class="pl-pds">`</span></span>, <span class="pl-c1">ProcessExited</span>(<span class="pl-c1">0</span>))

julia<span class="pl-k">&gt;</span> sh_deserialized <span class="pl-k">=</span> <span class="pl-c1">deserialize</span>(<span class="pl-s"><span class="pl-pds">"</span>/tmp/sh<span class="pl-pds">"</span></span>);   <span class="pl-c"><span class="pl-c">#</span> It's big now! :'(</span>

julia<span class="pl-k">&gt;</span> Humanize<span class="pl-k">.</span><span class="pl-c1">datasize</span>(Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>(sh_deserialized), style<span class="pl-k">=</span><span class="pl-c1">:bin</span>)
<span class="pl-s"><span class="pl-pds">"</span>2.0 MiB<span class="pl-pds">"</span></span></pre></div>