joeforker
joeforker

Reputation: 41787

Does CouchDB share map functions used by multiple views?

CouchDB's documentation says it supports multiple views with the same map function but different reduce functions. If both views are in the same design document then the map function will only be computed once.

Is this correct? Does the database compare the text of JavaScript map functions to decide whether to share the map?

Upvotes: 1

Views: 51

Answers (1)

Jonathan Hall
Jonathan Hall

Reputation: 79694

CouchDB itself does not do this. It's an implementation detail whether or not the query server does. In theory, the query server could cache functions for future sessions, giving a benefit similar to what you're describing.

In practice, I expect the performance gain would be minuscule for most interpreted languages, like javascript (since execution is already batched), so probably not worth it in the general case. It might be worth it for certain workloads, where you may want to write your own query server.

If using a query server for a compiled language (C, Java, Go, whatever), it probably would make sense to cache the compiled artifact for re-use.

Upvotes: 2

Related Questions