On your question:
dt[, .N, by="col1,col2"]
does actually not give you the number of unique rows, while either of these two do:
dt[, .N, by="col1,col2"][, .N] # data.table solution
nrow(dt[, .N, by="col1,col2"]) # data.frame syntax applied to data.table
My answer to your question:
A core feature of the data.table package is to work with a key. On p.2 from the short introduction to the data.table package it reads:
Furthermore, the rows are sorted by the key. Therefore, a data.table
can have at most one key, because it cannot be sorted in more than one
way.
Thus unless you have a column defining the sort order that you can set as key, the fact that your data are sorted, will be of no advantage. You thus need to set the key. For your purpose (large datafiles, thus assumingly many columns), you would want to include all of the columns in your dataset to set the key:
setkeyv(dt,c(names(dt))) # use key(dt) to check whether this went as expected
unique(dt)[, .N] # or nrow(unique(dt))
PS: please provide us a with a replicable dataset, so we can assess what you consider fast or slow.