Skip to content

bpo-32503: Avoid creating too small frames in pickles.#5127

Merged
serhiy-storchaka merged 4 commits into
python:masterfrom
serhiy-storchaka:pickle-small-frames
Jan 20, 2018
Merged

bpo-32503: Avoid creating too small frames in pickles.#5127
serhiy-storchaka merged 4 commits into
python:masterfrom
serhiy-storchaka:pickle-small-frames

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented Jan 7, 2018

Comment thread Lib/test/pickletester.py
frame_size = self.FRAME_SIZE_TARGET
num_frames = 20
obj = [bytes([i]) * frame_size for i in range(num_frames)]
obj = {i: bytes([i]) * frame_size for i in range(num_frames)}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, small integers don't produce a frame? Can you add a comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may misunderstand, actually...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added small objects (dict keys) between large objects.

Comment thread Lib/test/pickletester.py Outdated
# to the pickle's end.
frame_size = len(pickled) - last_pos - last_frame_opcode_size
self.assertEqual(frame_size, last_arg)
self.assertLessEqual(pos, frame_end)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated just below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I tried to write these tests in different forms and some checks are left duplicated.

Comment thread Lib/test/pickletester.py Outdated
if pos < frame_end:
self.assertNotIn(op.name, 'FRAME')
if op.name in frameless_opcodes:
self.assertLessEqual(len(arg), self.FRAME_SIZE_TARGET)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread Lib/test/pickletester.py Outdated
self.assertLessEqual(pos, frame_end)
self.assertLessEqual(pos, frame_end)
if pos < frame_end:
self.assertNotIn(op.name, 'FRAME')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks strange. Perhaps you meant assertNotEqual(op.name, 'FRAME')?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

Comment thread Lib/test/pickletester.py Outdated
self.assertLessEqual(len(arg), self.FRAME_SIZE_TARGET)
else:
frame_end = None
#frameless_start = pos
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like this should be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread Lib/test/pickletester.py
(op.name in frameless_opcodes and
len(arg) > self.FRAME_SIZE_TARGET)):
if frameless_start is not None:
self.assertLess(pos - frameless_start,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps comment on this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments!

@serhiy-storchaka
Copy link
Copy Markdown
Member Author

Thank you for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants