Your SlideShare is downloading. ×
0
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Pycon 2012 What Python can learn from Java

4,313

Published on

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,313
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
34
Comments
1
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. What Python can learn from JavaJonathan Ellis / @spycedPycon 2012
  • 2. (Not a web development perspective)
  • 3. The power of tools
  • 4. Remote debugging✤ -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044✤ 11 steps: “(6) install Wing IDE on the machine on which you plan to run your debug program... (8) copy wingdbstub.py into the same directory as your source files and import it in your Python source ... (10) In wingdbstub.py on your debug host, set kWingHostPort ... try setting kLogFile variable in wingdbstub.py for log additional diagnostic information.”
  • 5. JMX
  • 6. Triton
  • 7. GC in a nutshell✤ Mark✤ Sweep✤ Compact
  • 8. Aside: reference counting✤ Only good when allocation + assignment are relatively infrequent operations
  • 9. In short✤ Python has a terrible GC story✤ Poor instrumentation makes it worse
  • 10. Troubleshooting OOM
  • 11. Runtime profiling✤ https://github.com/foursquare/heapaudit✤ https://github.com/mariusaeriksen/heapster✤ Commercial: AppDynamics, DynaTrace, others
  • 12. Building blocks✤ -javaagent✤ ASM: http://asm.ow2.org/
  • 13. heapy http://guppy-pe.sourceforge.net/
  • 14. Collections✤ Less one-size-fits-all the more you care about performance ✤ HashMap ✤ ImmutableMap ✤ ImmutableSortedMap ✤ TreeMap ✤ ConcurrentSkipListMap ✤ ConcurrentLinkedHashMap ✤ SnapTreeMap ✤ NonBlockingHashMap✤ Not to mention BiMap, Multimap, ...
  • 15. Lists?✤ ArrayList✤ CopyOnWriteArrayList✤ ArrayBlockingDeque✤ LinkedBlockingDeque✤ PriorityQueue, PriorityBlockingQueue✤ SynchronousQueue✤ TransferQueue (Java7)
  • 16. Where are these in Python?✤ Python developers want to write Python, not C✤ Similar question: “Why not Cassandra in Python?”✤ PyPy to the rescue? ✤ RPython extension methods
  • 17. Growing a language (1998)✤ Guy Steele: “I should not design a small language, and I should not design a large one. I need to design a language that can grow.” ✤ http://www.cs.virginia.edu/~evans/cs655/readings/steele.pdf✤ Currently, Python is not a growable language
  • 18. Concurrency✤ ExecutorService, ThreadPoolExecutor ✤ FutureTask ✤ Also: ScheduledThreadPoolExecutor✤ ForkJoinPool
  • 19. Concurrency✤ For CPU-bound applications, copies are the enemy ✤ Useful but dangerous: ✤ List.subList, NavigableMap.subMap✤ Corollary: you need to support threads + shared state ✤ Twisted ✤ Actor model ✤ Multi-process + sysv✤ Local and remote computation: one size does not fit all
  • 20. Copies are bad✤ Copies of large things are especially bad ✤ Remember fragmentation?✤ Iterators (generators) are good ✤ Java: ByteBuffer ✤ Python: memoryview
  • 21. The GIL✤ The GIL offers negligible help writing concurrent code✤ Consider this trivial race condition: if d[k] == v1: d[k] = v2
  • 22. More subtle problems✤ Which of these is threadsafe? ✤ L.append(x) ✤ x = x + 1 ✤ x += 1
  • 23. More subtle problems✤ Which of these is threadsafe? ✤ L.append(x) ✤ x = x + 1 ✤ x += 1✤ “The thread safety of python operations depends on the compilation of python statements into byte-codes, which is an implementation detail and should not be relied upon.”
  • 24. Are we stuck with explicit locks?✤ ConcurrentMap ✤ boolean replace(key, oldValue, newValue) ✤ NonBlockingHashMap✤ BlockingQueue✤ CopyOnWriteArrayList
  • 25. Shared state good, Mutable state bad✤ final: most under-appreciated language feature?✤ guava: Immutable collections ✤ http://code.google.com/p/guava-libraries/✤ Persistent collections ✤ (More accurately, “What Python can learn from Haskell”) ✤ http://code.google.com/p/pcollections/ ✤ SnapTreeMap
  • 26. Final thoughts✤ JRuby is the most advanced Ruby implementation✤ Jython is less popular, but I’d rather write Java than C✤ Once you can write Python libraries that rival native ones for speed, things will get much more interesting

×