0

I'm working with Earthengine with a commercial license now so I started worrying about the performance of my computations. As the caching mechanism is preventing me from doing performance checks on my own, I'll ask it here and maybe a GEE developer will pass by.

Should I prefer using map or iterate when looping on a collection?

sequence = ee.List.sequence(1000) 

# map version 
featureList = sequence.map(lambda i: ee.Feature(point, {"id": i}))

# iterate 
featureList = sequence.iterate(
    lambda i, l: ee.List(l).cat(ee.List([ee.Feature(point, {"id": i})])), 
    ee.List([])
)

In this example, I would of course go for the map for readability but there are more tricky situations where forcing myself to think with map is taking more time than a good old iterate.

1 Answer 1

1

I can't tell what you're really trying to do, but there are no situations where you can use both map and iterate where you should choose iterate. You should also avoid converting to list when possible..

Also, using the profiler should turn off all caching.

4
  • thanks for your answer, here is a small test my colleague sent me where we didn't saw any diff between the 2 profiled processes: code.earthengine.google.com/8ce62db02a2768eecc12c6ccbb50da8d Commented Nov 9, 2023 at 6:53
  • Those examples are so small that the normal noise is probably 50% of the expense, however the mapped version is clocking in at about 30% cheaper EECUs. If you did this by ~1000x then you might have numbers that are believeable. Commented Nov 9, 2023 at 14:40
  • Thanks @NoelGorelick for your answer. I have a follow up question (I don't think it's enough to be a new thread by itself): profiler turns off all caching also in python? Commented Nov 14, 2023 at 22:30
  • Yes. It's a backend flag. Commented Nov 16, 2023 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.