首页 > 解决方案 > 将大对象传递给函数会影响速度吗?

问题描述

传递大型 json-object message

def foobar(message):
    ...

@bot.message_handler(content_types=['text'])
def text_handler(message):
    foobar(message)

只传递两个字符串:

def foobar(chat_id, text):
    ...

@bot.message_handler(content_types=['text'])
def text_handler(message):
    foobar(message.chat.id, message.text)

标签: pythonpython-3.xperformanceobject

解决方案


Python 始终使用“按引用传递”模型。所以根据定义,它不应该直接影响你的代码性能。但是,处理较大的对象可以。


推荐阅读