should I cache simple classes that used intensive?
<p>I'm writing HFT trading software. I'm trying to optimize it. I figured out that every second I create several thousands of <code>Instrument</code> object, the source code of this class below:</p>

<pre><code>public class Instrument
{

    public int GateId { get; set; }
    public string Ticker { get; set; }
    public override string ToString()
    {
        return "GateID: " + GateId + " Ticker: " + Ticker + '.';
    }

    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return false;
        }
        Instrument instrument = obj as Instrument;
        if (instrument == null)
        {
            return false;
        }
        return (GateId.Equals(instrument.GateId)) &amp;&amp; (Ticker.Equals(instrument.Ticker));
    }

    public override int GetHashCode()
    {
        int hash = 13;
        hash = (hash * 7) + GateId;
        hash = (hash * 7) + Ticker.GetHashCode();
        return hash;
    }
}
</code></pre>

<p>Actual number of Instruments is pretty limited. It's about 100 totally. But I constantly create the same Instrument object many times per second, like that:</p>

<pre><code>new Instrument { GateId = 0, Ticker = "MSFT" }
</code></pre>

<p>I.e. I have many instances of "MSFT" Instrument but I can use them in HashSet/HashMap or whereever thanks to overriden <code>Equals</code> and <code>GetHashCode</code> methods.</p>

<p>But now I think if it makes sense to have at runtime 10 or 100 "MSFT" <code>Instrument</code> object (that are equals to each other).</p>

<p>So I want to create something like that:</p>

<pre><code>interface InstrumentFactory {

    public Instrument GetInstrument(int GateId, string Ticker);

}
</code></pre>

<p>Every time I need some instrument I just want to ask InstrumentFactory. InstrumentFactory will store my 100 instruments in HashSet internally and just will return cached copy. Also I now can remove <code>Equals</code> and <code>GetHashCode</code> methods as I have exactly one <code>Instrument</code> for each gateId + ticker pair.</p>

<p>Questions:</p>

<ul>
<li>with new approach will I have noticable perfomance improvements?</li>
<li>what do you thing about new design? when I frequently need same objects is it better to use <code>factory</code> instead of creating new object every time with overriden Equals and GetHashCode methods?</li>
</ul>
