4 DebugRelease Armin Ronacher

2020-03-01 127浏览

  • 1.DEBUG IS THE NEW
  • 2.THE UNEXPECTED BENEFITS OF SLOW
  • 3.ARMIN @MITSUHIKO RONACHER / FLASK, WERKZEUG, JINJA, CLICK, … / DIRECTOR OF ENGINEERING AT
  • 4.
  • 5.1. developer experience matters 2. the ability to debug matters 3. debugging does not stop when shipping a release
  • 6.Python 3.7.4 (default, Jul 9 2019, 18:13:23) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> a_variable = 'Hello World!' >>> sys._getframe().f_locals['a_variable'] 'Hello World!'
  • 7.RUNTIME INTROSPECTION
  • 8.RUNTIME INTROSPECTION
  • 9.RUNTIME INTROSPECTION
  • 10.S K R O W “ N MY O ” E N I H C A M
  • 11.MILLIONS OF BROWSER SESSIONS HUNDREDS OF COUNTRIES
  • 12.IOT DEVICES MOBILE PHONES
  • 13.LET'S DEBUG
  • 14.you need basic debugging and introspection in production
  • 15.PROD VS DEBUG PERF
  • 16.let's talk about runtimes …
  • 17.Simple Interpreter JIT compiled AOT compiled
  • 18.• these are examples • not scientific • not entirely comparable
  • 19.INTER PRETER
  • 20.A SimpleInterpreter:CPython
  • 21.>>> import dis >>> >>> def add_numbers(a, b): ... return a + b ... >>> dis.dis(add_numbers) 2 0 LOAD_FAST 2 LOAD_FAST 4 BINARY_ADD 6 RETURN_VALUE 0 (a) 1 (b)
  • 22.while ... { switch (...) { case TARGET(LOAD_FAST): { PyObject *value = GETLOCAL(oparg); if (value == NULL) { format_exc_check_arg(tstate, PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, PyTuple_GetItem(co->co_varnames, oparg)); goto error; } Py_INCREF(value); PUSH(value); FAST_DISPATCH(); } }
  • 23.case TARGET(BINARY_ADD): { PyObject *right = POP(); PyObject *left = TOP(); PyObject *sum; if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { sum = unicode_concatenate(tstate, left, right, f, next_instr); } else { sum = PyNumber_Add(left, right); Py_DECREF(left); } Py_DECREF(right); SET_TOP(sum); if (sum == NULL) goto error; DISPATCH(); }
  • 24.there is a lot of compiled code executing every instruction
  • 25.import sys def failing_func(): raise Exception('Oh noes') def catching_func():try:'>try: