# Very slow write and count operations after densify

**URL:** <https://discuss.hail.is/t/very-slow-write-and-count-operations-after-densify/3094>\
**Category:** Hail Query & hailctl\
**Created:** [January 31, 2023, 3:37pm UTC](https://discuss.hail.is/t/very-slow-write-and-count-operations-after-densify/3094 "2023-01-31T15:37:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arm](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@arm](https://discuss.hail.is/u/arm)\
**Post date:** [January 31, 2023, 3:37pm UTC](https://discuss.hail.is/t/very-slow-write-and-count-operations-after-densify/3094/1 "2023-01-31T15:37:29Z")

</div>

Hello Hail team!

I am attempting to read in a matrix table, perform a densify operation, then filter to a subset of the data and mt.write(). The filter operations are being performed quickly, as I’d expect, but the mt.write() operation has been running for over an hour and is still nowhere near done.

The original mt is a huge amount of data, count() returns (2736925182, 7783). We filter it down to just CHR 22 of ~500 of these individuals, however, before the write operation.

Is there any way to speed up the code?

import hail as hl  
hl.init(default\_reference=‘GRCh38’)  
import argparse

import numpy as np  
import pandas as pd  
from [bokeh.io](http://bokeh.io) import show, output\_notebook  
from bokeh.layouts import gridplot  
output\_notebook()

mt = hl.read\_matrix\_table(‘gs://filepath.sparse.mt/’)  
mt = hl.experimental.densify(mt)

# filter to chr22

intervals = [‘chr22’]  
mt = hl.filter\_intervals(mt, [hl.parse\_locus\_interval(x, reference\_genome=‘GRCh38’) for x in intervals])

#filter to test individuals  
ppmi\_ids = df[0]  
samples\_to\_keep = set(ppmi\_ids)  
set\_to\_keep = hl.literal(samples\_to\_keep)  
test\_data = mt.filter\_cols(set\_to\_keep.contains(mt.meta.external\_id))

# Save mt densified and filtered to CHR22/PPMI

test\_data.write(‘gs://dataproc-staging-us-east1-942231253036-bw4veo0a/test\_start.mt/’, overwrite=True)
