# .Q.en with huge amount of symbols

**URL:** <https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [January 13, 2015, 7:22pm UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379 "2015-01-13T19:22:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![skuvvv1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skuvvv1](https://forum.kx.com/u/skuvvv1)\
**Post date:** [January 13, 2015, 7:22pm UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/1 "2015-01-13T19:22:00Z")

</div>

I made test DB with 1mil+ symbols.  
Next time when I use .Q.en on empty table it consume high amount of cpu(1 core full load).

Any comments please.

eg I use \t:1000

and z.ts with func inside:

`"TradesHeader: ([]Time:`time$();Symbol:`symbol$();Price:`float$();Size:`int$();Dir:`byte$();OI:`int$();Id:`int$();Ex:`symbol$());`  
Result below:

Blue - CPU thread load for q

Red - Total CPU load

![]()

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [January 13, 2015, 7:28pm UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/2 "2015-01-13T19:28:00Z")

</div>

symbol type is suitable for repeating strings. Other datatypes should be used for strings that are unique or repeat infrequently.

.Q.en reloads the sym file, then appends new symbols. You are probably obersving the cost of creating 1M+ symbols (first run interns them, further runs look up in the hastable).

sym mem usage can be seen via .Q.w.

---

<div class="post-metadata">

**Author:** ![skuvvv1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skuvvv1](https://forum.kx.com/u/skuvvv1)\
**Post date:** [January 13, 2015, 10:40pm UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/3 "2015-01-13T22:40:00Z")

</div>

Yes, all my symbols repeating and used often, Symbol - instrument name, Ex - exchange name.  
I was surprised that CPU load was on empty table when nothing was to enumerate.

If .Q.en reload sym file it&nbsp;explains a lot.

Does other way to enumerate symbol? I mean without reloading them to avoid further CPU loads.

Something like checking new symbol in hashtable, next append if necessary to hashtable and to disk sym file.

It should be faster.

---

<div class="post-metadata">

**Author:** ![Ryan\_Hamilton1](https://avatars.discourse-cdn.com/v4/letter/r/82dd89/32.png) [@Ryan\_Hamilton1](https://forum.kx.com/u/Ryan_Hamilton1)\
**Post date:** [January 13, 2015, 11:28pm UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/4 "2015-01-13T23:28:00Z")

</div>

Hi Vadim,

You could create a modified .Q.en to enumerate against an in-memory variable:

q)t:( `$string til 1200300) q)\t:100 `:u/ upsert .Q.en[`:.;t] 26118 q)k)qen:{if[#f@:&11h=@:'x f:!+x;`sym??,/?:'x f;];@[x;f;`sym?]} q)\t:100 `:v/ upsert qen t  
9818

It has more than halved the time in this case, though make sure to save the sym to disk.  
While giving the same result:

q)\l .  
q)(select from u)~(select from v)  
1b

This does mean however that you can’t have multiple processes writing to the same folder as there is now no automatic file lock on the sym file.

If you really wanted to offload the cpu cost from the q process you could enumerate the data in the loading process.

Regards,  
Ryan

–  
www.timestored.com - kdb training  
Tel: +44 (0) 20 3397 7535  
Email: ryan@timestored.com

---

<div class="post-metadata">

**Author:** ![skuvvv1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skuvvv1](https://forum.kx.com/u/skuvvv1)\
**Post date:** [January 21, 2015, 10:37am UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/5 "2015-01-21T10:37:00Z")

</div>

Thanks Ryan!

It solved problems.

I found strange situation with \x

when I remove .z.zd using system"x " it not completed, looks like a bug.

![]()

ps I want to do upsert(11h variable) to a sym file, but I use compression and should disable it before upserting.

Does other way exist to do this in function?

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [January 21, 2015, 10:49am UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/6 "2015-01-21T10:49:00Z")

</div>

q).z.zd:{}

q)system"x .z.zd"

q).z.zd

'.z.zd

---

<div class="post-metadata">

**Author:** ![skuvvv1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skuvvv1](https://forum.kx.com/u/skuvvv1)\
**Post date:** [January 21, 2015, 10:56am UTC](https://forum.kx.com/t/q-en-with-huge-amount-of-symbols/9379/7 "2015-01-21T10:56:00Z")

</div>

So simple -)  
thanks.

2015-01-21 14:49 GMT+04:00 Charles Skelton \<charlie@kx.com\>:

> q).z.zd:{}
> 
> q)system"x .z.zd"
> 
> q).z.zd
> 
> '.z.zd
